[Tutor] Unpacking lists
Alan Gauld
alan.gauld at btinternet.com
Wed Jul 9 08:16:39 CEST 2014
On 09/07/14 06:58, Alan Gauld wrote:
>> list1 = [1, 8, 15]
>> list2 = [2, 9, 16]
>> list3 = [[3, 4, 5, 6], [10, 11, 12, 13], [17, 18, 19, 20]]
>> list4 = [7, 14, 21]
> I'm thinking something like
>
> result = []
> for L in (list1,list2,list3):
> if isinstance(L,list)
> result += L
> else: result.append(L)
>
> mebbe...
Too early in the morning...
There needs to be another loop around that.
for L in (list1,list2,list3):
for index in len(list1): #???
if isinstance(L[index],list)
result += L[index]
else: result.append(L[index])
double mebbe.
Anyway I'm off to work... :-)
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list