I recently got help with fixing a function that changes elements in a list when printing said list. However, my program demands me being able to revert whatever changes I've made to an element in the list. Judging from the code, this should be doable with what I have, but it seems I can't alter the list once it has been altered once. The affected code looks like this:
def seatingmap():
# The parameters of seating-plan
rows = 6
seats = 4
seat_rows = [i for i in range(1, rows * seats + 1)]
seat_rows = [seat_rows[i:i + seats] for i in range(0, len(seat_rows), seats)]
return seat_rows
def find_in2Dlist(lst, item):
for index, sublist in enumerate(lst):
try:
aname = sublist.index(item)
return [index, aname]
except:
continue
return None
def printList(mlist, chosenseat):
i = 0
temp = mlist.copy()
while i < len(chosenseat):
findseat = find_in2Dlist(mlist, chosenseat[i])
if findseat == None:
i += 1
else:
temp[findseat[0]][findseat[1]] = '*' + str(temp[findseat[0]][findseat[1]]) + '*'
i += 1
for idx, row in enumerate(temp):
if idx == len(temp) // 2:
print("{:^{}}".format('↓ TYST AVD ↓', (len(row) * 4) - 2))
if idx % 2 == 1:
row = row[::-1]
print(("{:<4}" * len(row)).format(*row))
list = seatingmap()
number = [2]
printList(list, number)
number = [2,4]
printList(list, number)
Edit
If I for example run the code above, it changes this:
1 2 3 4
8 7 6 5
9 10 11 12
↓ TYST AVD ↓
16 15 14 13
17 18 19 20
24 23 22 21
To this:
1 *2* 3 *4*
8 7 6 5
9 10 11 12
↓ TYST AVD ↓
16 15 14 13
17 18 19 20
24 23 22 21
Which is good. Although, now I want be able to change it back to let's say:
1 2 3 *4*
8 7 6 5
9 10 11 12
↓ TYST AVD ↓
16 15 14 13
17 18 19 20
24 23 22 21
By removing the "2" from "chosenseats". This is where I'm stuck, as when I attempt to do this, it prints out the same list as before the 2 was removed.Is there any way I can go about this issue?