r/Python • • Oct 27 '14

Help me understand a bit about lists

i have this code

list1 = [ ['user1', '18/02/1996', '999999999'], ['user2', '19/02/1997', '888888888'] ]

for x in list1:

print(x)
for user, date, number in x:
    print(user, date, number)

and it doesn't work, anyone can help me?

0 Upvotes

6 comments sorted by

5

u/karmarauder Oct 27 '14

0

u/Tuganazy Oct 27 '14

But can you help me out here? I will post noob questions on there from now on

-1

u/thisisthemurph Oct 27 '14
list1 = [ ['user1', '18/02/1996', '999999999'], ['user2', '19/02/1997', '888888888']] 
for name, date, num in list1:
    print(name, date, num) 

Here what you are doing is looping through each element of the initial list but unpacking the lists with the details into the specified variables.

0

u/Tuganazy Oct 28 '14

That fixed , tks

1

u/POTUS Oct 27 '14

I'll give you a hint: You have one extra for statement.

0

u/thisisthemurph Oct 27 '14

Ensure your code is formatted correctly in your question. What error are you getting? A description of the error always helps.