Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extraction of elements of tuples

Tags:

Given one list with one tuple:

[{4,1,144}] 

How to extract the first element of the tuple inside the list:

element(1,lists:nth(1,L)) 

Do you have a simpler solution?

like image 707
Bertaud Avatar asked Jan 27 '11 17:01

Bertaud


People also ask

How do you extract an element from a tuple?

To extract the n-th elements from a list of tuples with Python, we can use list comprehension. We get the n-th element from each tuple and put them into a list with [x[n] for x in elements] . x is the tuple being retrieved. Therefore, e is [1, 3, 5] .

How do you extract a tuple list?

If it is required to extract the rear element from a list of tuples, it can be done using list comprehension and negative indexing. The list comprehension is a shorthand to iterate through the list and perform operations on it.

How do you find the elements in a list of tuples?

In the majority of programming languages when you need to access a nested data type (such as arrays, lists, or tuples), you append the brackets to get to the innermost item. The first bracket gives you the location of the tuple in your list. The second bracket gives you the location of the item in the tuple.


1 Answers

Try this:

1> A = [{3,1,1444}]. [{3,1,1444}] 2> [{X, _, _}] = A. [{3,1,1444}] 3> X. 3 4>  
like image 162
0xAX Avatar answered Nov 07 '22 06:11

0xAX