#File: ChapterLists/deleteItem.py """ Removes first occurence if x in L: L.remove(x) Delete index. First check if x is there then find index (the position ) in the list L = [5, 3, 4, 6, 5] Enter a number to delete? 5 L = [3, 4, 6, 5] L = [5, 3, 4, 6, 5] Enter a number to delete? 5 L= [5, 3, 4, 6, 5] index of x in L= 0 L = [3, 4, 6, 5] """ #solution 1 L = [5, 3, 4, 6, 5] print("L = ", L) x = int(input( "Enter a number to delete? " ) ) if x in L: L.remove(x) print("L = ", L) #solution 2 L = [5, 3, 4, 6, 5] print("L = ", L) x = int(input( "Enter a number to delete? " ) ) if x in L: print("L=", L, "index of x in L=", L.index(x)) del L[ L.index( x ) ] #find index of x and delete x print("L = ", L)