[Tutor] Dynamic naming of lists

Ian D duxbuz at hotmail.com
Tue Mar 31 16:00:53 CEST 2015


Hi

I have a list that I am splitting into pairs of values. But the list is dynamic in size. It could have 4 values or 6 or more.

I originally split the list into pairs, by using a new list and keep a pair in the old list by just popping 2 values. But if the list is longer than 4 values. I cannot do this. I can only envision I would need to dynamically create lists. How would I do this?

while returned_list_of_items:
    for i in range(1):
        new_list.append(returned_list_of_items.pop(0)) #pop first value and append
        new_list.append(returned_list_of_items.pop(0)) #pop second value and append

Thanks 		 	   		  


More information about the Tutor mailing list