954,515 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Nested lists indexing

Im trying to get the last element in each nested list
such as

double list = [['Hello','how','are','you'],['I','am','fine'],['How','about','yourself']]
so that it will print out ['you','fine','yourself]

I am also trying to do this all under a function such as

def last_words():
#where my double_list is already in this function

Thank you!

effBlam
Newbie Poster
13 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 
print( [x[-1] for x in double_list] )
Gribouillis
Posting Maven
Moderator
2,786 posts since Jul 2008
Reputation Points: 1,044
Solved Threads: 691
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: