I
Iain King
I was playing with list comprehensions, to try and work out how doubled
up versions work (like this one from another thread: [i for i in
range(9) for j in range(i)]). I think I've figured that out, but I
found something strange along the way:
'three']]
'three']]
Shoudn't both lines '[x for x in y for y in beta]' produce the same
list?
I'm guessing I'm the one confused here... but I'm confused! What's
going on?
Iain
up versions work (like this one from another thread: [i for i in
range(9) for j in range(i)]). I think I've figured that out, but I
found something strange along the way:
[['one', 'two', 'three'], ['one', 'two', 'three'], ['one', 'two',alpha = ["one", "two", "three"]
beta = ["A", "B", "C"]
[x for x in alpha for y in beta] ['one', 'one', 'one', 'two', 'two', 'two', 'three', 'three', 'three']
[x for x in y for y in beta] ['C', 'C', 'C']
beta = [alpha, alpha, alpha]
beta
'three']]
[['one', 'two', 'three'], ['one', 'two', 'three'], ['one', 'two',[x for x in y for y in beta] ['C', 'C', 'C']
[y for y in beta]
'three']]
['one', 'one', 'one', 'two', 'two', 'two', 'three', 'three', 'three'][x for x in y for y in beta]
Shoudn't both lines '[x for x in y for y in beta]' produce the same
list?
I'm guessing I'm the one confused here... but I'm confused! What's
going on?
Iain