3

Matches an item in the tuples list

 3 years ago
source link: https://www.codesd.com/item/matches-an-item-in-the-tuples-list.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Matches an item in the tuples list

advertisements

I have a List of tuples of the form (string, int). I'm trying to search through the list and return the tuple whose string component matches the parameter, as in: let find_tuple string_name tuples_list =

How can I do this? I can't quite wrap my head around it. Is there a way to use matching syntax like (string, _) ->...?


You can achieve this as following

let rec find_tuple string_name tuples_list =
       match tuples_list with
            [] -> raise Not_found
            |(s, i)::tl -> if s = string_name then (s, i)
                                  else find_tuple string_name tl

or simply

List.find (fun s -> fst s = string_name) tuples_list

Related Articles

Is it possible to paste a list into a select2 field and match each item in the list?

I am using Select2 to manage large lists of data. Users have expressed a desire to be able to paste a list to the Select2 field in order to select various items at once instead of manually entering and matching each item in the list. I have attempted

Return of the first value of the tuples list

I'm learning to deal with Lists and Tuples in F# and a problem came up. I have two lists: one of names and one with names,ages. let namesToFind = [ "john", "andrea" ] let namesAndAges = [ ("john", 10); ("andrea", 15

SQL Procedure Error - The INSERT statement contains more items than the insert list

Error: Msg 121, Level 15, State 1, Procedure InsertNonExistingNode, Line 5 The select list for the INSERT statement contains more items than the insert list. The number of SELECT values must match the number of INSERT columns. Procedure in SQL Manage

How to extract a tuple that contains an element from the tuple list?

I have this list of tuples: [{denomination_flexible_denomination,236,9,2,"1","CORE BALANCE",0,10,"1","500","100","100",null,"ecrlrlep_facilito","ecrlrlep_facilito","true&

How can I remove items from the generic list, depending on several conditions and using linq

I have two lists, one containing urls and another, containing all MIME file extensions. I want to remove from the first list all urls that point to such files. Sample code: List<string> urls = new List<string>(); urls.Add("http://stackove

How to find the index of the item with the shortest list inside?

So I have a list in this format: lst = [[x1, y1, [1,3,4]], [x2, y2, [6,3]], [x3, y3, [8,6,3,9]]] I want to find the index of item with the shortest list inside. i.e. In this case it would return [x2, y2, [6,3]] since [6,3] is the shortest list in thi

Android: Get an item from the navigation list actionbarsherlock

I have used actionbarsherlock library, in that i have used NavigationList and binded following data: get Item from the navigation list: Cursor cCategory = dbh.getCategory(); final String [] cName = new String[] {DatabaseHelper.CATEGORY_NAME}; int to[

jQuery slips the item into the sortable list that has the initial state as hidden

I can't seem to drag an element into sortable list that has initial state as hidden (ie. display:none). Each row's html looks like this: <div class="dragbox" id="item1" > <h2>Expression 1<span id="exp1"><

How to align the text in a list item if the previous list item is higher than

How do you middle align text in a list item if the previous list item is heigher than it? I have the following HTML code: <ul class="list-inline"> <li style="background-color: aqua;"> <div style="height:50px;width:5

Python: lists in lists - function that adds a string to the item in the parent list without affecting the list of children?

I have generated a list of lists using: board = [] for i in range(0,5): board.append(["#"] * 4) Which returns: [['#', '#', '#', '#'], ['#', '#', '#', '#'], ['#', '#', '#', '#'], ['#', '#', '#', '#'], ['#', '#', '#', '#']] And have made them prin

removing the last item from the navigation list

im struggling to remove the "pipe" border i have on the last item of the nav list- my code- <div id="header"> <ul id="menu"> <li><a href="">Home</a></li> <li><a href=&quo

Analyze the data via `re.match` and place it in tuple / list / dictionaries

I am currently parsing a large amount of data (user data) and matching it into various groups to for later use. Im not sure on the best approach do I place the data into a tuple list like so [(data1value,data2value,data3value,data4value)]. Then conve

Counting the number of items in a tuple list in Erlang

I have the following List structure: [{A, [{B <--, [A, C]}, {C <--, [B, A]}]}, {B, [{C <--, [A, C]}]}] For example, B = 1, C = 2. What would be the correct way to do so? UPDATE I'd like to count the number of <-- (a symbol I added just to show

Python list.remove the items in the second list

I've searched around and most of the errors I see are when people are trying to iterate over a list and modify it at the same time. In my case, I am trying to take one list, and remove items from that list that are present in a second list. import py

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK