Crypticlaugh Crypticlaugh - 1 month ago 8
Python Question

How do I delete strings from a list in a certain order without typing it's value?

I already know how to delete strings but the question here is how do you delete them in a certain order without typings it's value for ex. "Mathew" but, I want to remove it without actually typing "Mathew" and without removing the value "Paul". Is there any way behind this?

Note that "Paul" is the first string in the list so I do not want to remove but this but the second string if it is possible.

usernames = ["Paul", "Mathew"]
del_username = usernames.remove("Mathew")


I have tried adding a '1' to the .remove function but it cant find the value somehow.

del_username = usernames.remove(1)


Edit: How do I delete a string using the 'input()' function?

I have tried this

for options in range (True):
name_add = names.append(input("1. Add another name: "))
name_add = del.names (input("2. Type a number in the certain list order name to remove "
"that name: "))


Gives me an 'invalid syntax' error.

Answer

To remove the item at index i, use del

names = ["Paul", "Mathew"]
del names[1]
print(names)

outputs

["Paul"]
Comments