0

I have the following list:

x =['Adam', 'G', '24', '1983', 'Aug', 'August Birthday', 'Steve', 'F', '31', '1970', 'Sep', 'sept bday']

I would like to get the above list into another list but in a way I can work with it like this

x = [('Adam', 'G', '24', '1983', 'Aug', 'August Birthday'),('Steve', 'F', '31', '1970', 'Sep', 'sept bday')]

The Pattern is x = [(0,1,2,3,4,5),(0,1,2,3,4,5)] etc....

What is a good way to do this?

I have tried to iterate over the list using a count and after each line adding 1 to the count so I can get to 6 then start count over again, but I am not sure how to get it into the desired list.

BenMorel
  • 31,815
  • 47
  • 169
  • 296
Trying_hard
  • 8,103
  • 25
  • 57
  • 81
  • It may also be worth looking at how that first list is generated in the first place and changing that unless you also need it in the long format. – kylieCatt Jan 08 '14 at 20:42

1 Answers1

3
size_of_new = 5
print zip(*[iter(x)]*size_of_new)

is my favorite way of doing this ... however

[x[i:i+size_of_new] for i in range(0,len(x),size_of_new)]

is maybe more readable

Joran Beasley
  • 103,130
  • 11
  • 146
  • 174