python - Separate a list into sublists? -


i have list this:

l = ['a,b,c,d' , 'a,b,c,d', 'a,b,c,d', 'a,b,c,d'] 

and want make list formatted this:

l = [['a,b,c,d'],['a,b,c,d'],['a,b,c,d'],['a,b,c,d']] 

or 4 separate lists fine, want able iterate through every element in each sublist. have far:

for string in range(0, len(userlist)):     small_list = userlist[string:]     print(small_list) 

this not separate list lists want however. i'm thinking have break list off chunks of 4.

you can list comprehension:

l = [s.split(",") s in l] # result: [['a', 'b', 'c', 'd'], ['a', 'b', 'c', 'd'], ['a', 'b', 'c', 'd'], ['a', 'b', 'c', 'd']] 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -