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?
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] .
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.
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.
Try this:
1> A = [{3,1,1444}]. [{3,1,1444}] 2> [{X, _, _}] = A. [{3,1,1444}] 3> X. 3 4>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With