+ 1

Trying to figure this out

#!/usr/bin/python3 list0 = [] list1 = [] list2 = [] table = [list0, list1, list2] count = 0 for t in table: for i in range(4): t.append(str((count * 4) + i + 1)) print(" ".join(t)) count += 1 I understand what the code is doing by adding items to the lists and then printing the contents of these lists. I’m a little confused making sense of the code in the ‘append’ line. Thanks

11th Aug 2019, 5:10 AM
Pappy
1 ответ
+ 5
Handtrace it. When t is list0, count is 0: 0 * 4 + 0 + 1 = 1 0 * 4 + 1 + 1 = 2 0 * 4 + 2 + 1 = 3 0 * 4 + 3 + 1 = 4 When t is list1, count is 1: 1 * 4 + 0 + 1 = 5 1 * 4 + 1 + 1 = 6 1 * 4 + 2 + 1 = 7 1 * 4 + 3 + 1 = 8 When t is list2, count is 2: 2 * 4 + 0 + 1 = 9 2 * 4 + 1 + 1 = 10 2 * 4 + 2 + 1 = 11 2 * 4 + 3 + 1 = 12
11th Aug 2019, 5:46 AM
Hatsy Rei
Hatsy Rei - avatar