The title of the question is pretty much what I'm interested in!
Let's say I have a list of tuples:
tuple_list = [(1,'a'),(2,'b'),(3,'c')]
What will I use to indicate all the first elements of tuple_list? What I would like to return is a list of the first elements. Just like tuple_list.keys () would work if it were a dictionary. Like this:
(tuple_list expression here) = [1,2,3]
Is it possible? Is there a simple expression or will I need to go through tuple_list and create a separate list of the first elements this way?
Also, the reason I want to do this is because I want to do the following:
first_list = [(1,'a'),(2,'b'),(3,'c')] second_list = [1,2,3,4,4,5] third_list = set(second_list) - set(first_list(**first elements expression**)) = [4,5]
I am adapting this for lists from some old code that used dictionaries:
first_dict = {1:'a',2:'b',3:'c'} second = [1,2,3,4,4,5] third_dict = set(second) - set(first_dict.keys()) = [4,5]
Therefore, my dilemma with the lack of .key () for lists
As always, please comment if I can improve / clarify the question in any way.
Thanks,
Alex