Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unintended output
#1
j = [['4', '5'], ['1', '1'], ['1', '5'], ['3', '4'], ['3', '1']]
k = [['5', '2'], ['4', '2'], ['2', '4'], ['3', '3'], ['4', '3']]
t = [[None] *2] *50
indexPointer = 0


for coord in j:
    print(coord)
    for number in coord:
        t[indexPointer][0] = number
        indexPointer += 1
indexPointer = 0
for coord in k:
    for number in coord:
        t[indexPointer][1] = number
        indexPointer += 1
print(t)
The output is:

[['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3'], ['1', '3']]

The output should be: 

[['4','5'],['5','2'],['1','4'],['1','2'],['1','2'],['5','4'],['3','3'],['4','3'],['3','4'],['1','3']]
Reply


Messages In This Thread
Unintended output - by Nick_Wright - Dec-05-2016, 09:24 PM
RE: Unintended output - by micseydel - Dec-05-2016, 09:29 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020