Dictionary with Tuples in Python

+1 Alex Williams · November 22, 2015
How would you find lets say an individual element of dictionary if the key has a value that is a tuple or list. For example:
letter={a:( 'alex','andre','atiba')} 

what would you do to get 'alex?

Post a Reply

Replies

Oldest  Newest  Rating
0 alex constantin · November 22, 2015
You would do:
t = letter['a'] #get to the tuples
alex = t[0] #get the first element, which is alex

#or simply:

alex = letter['a'][0]

  • 1

Python

107,121 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator