How can i have a tuple that has a list as a value.
F.x. if i want to have a structure like this.
( Somechar , Somelist[] )
And how would i iterate through a dictionary of these things?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can add a list to a tuple just like any other element. From a dictionary, you can access each element of the tuple by indexing it like so:
d[key][0]andd[key][1]. Here is an example:>>> d = {} >>> d["b"] = ('b', [2]) >>> d["a"] = ('a', [1]) >>> for k in d: ... print(d[k][0], d[k][1]) ... ('a', [1]) ('b', [2])