I have list items as below. Want to delete particular list within this list. When user enter phone number, it check with list and get particular list which have matched phone number list and then delete that particular list and display rest of list.
account= [['abc', 8566665891, 's', 5000], ['xyz', 9852560352, 'c', 6000], ['pqr', 6854265891, 's', 7000]]
c_phone = int(input("Enter your phone to Close Account : "))
for a, b, c, d in account:
if c_phone == b:
del account[b]
print(account)
the result will be:
Enter your phone to Close Account : 9852560352
[['abc', 8566665891, 's', 5000], ['pqr', 6854265891, 's', 7000]]
del x[i]to delete the element with indexifrom listx. The list is destructively modified. More generally, you can dodel x[i:j:k]to delete a slice from listx.