I recently started learning python and working with arrays. I need to check if inside my array an inputted code exists abd if it does delete the whole list that contains it. My code is the following:
room = 'F22'
array = [['F22', 'Single', 'Cash']]
def deleteReservation(room, array):
print(array)
for x in array:
for i in x:
if room in i:
index = array.index(room)
mode = validateNum(0, '1 To confirm, 2 to cancel.: ', 3)
if mode == 1:
array = array.pop(index)
return array
elif mode == 2:
return 'Canceled.'
else:
return "Reservation was not found."
But I keep getting the following mistake:
Traceback (most recent call last):
index = array.index(room)
ValueError: 'F22' is not in list
My guess is that the error is inside the nested loop, but I can't find it.