1

I feel like I am missing something basic here. It seems to have different results from identical input based on how the input was generated.

This is a simplified version of the problem which exists in a much larger code base, so please excuse any oddities as I am trying to figure out the reason for this discrepancy, not to fix this particular piece of code.

from __future__ import print_function

def wtf(thing):
    list(thing)
    for i in range(0, 4):
        print(len(thing[i]),)
        while len(thing[i]) < 10:
            thing[i].append(None)
    print()

# Generated by method1
test1  = [[None]]*4

# Generated by method2
test2 = []
for b in range(4):
    test2.append([None])


print(test1==test2)

print()

print(test1, type(test1))
wtf(test1)

print()

print(test2, type(test2))
wtf(test2)

output

True

[[None], [None], [None], [None]] <type 'list'>
1
10
10
10


[[None], [None], [None], [None]] <type 'list'>
1
1
1
1

0 Answers0