output ==> ['s', 't', 'u', 'f', 'w', 'x', 'y', 'y']
this is the output I get, how can I get rid of one of the y letters?
CodePudding user response:
I think you are trying to remove duplicates from your list.
So, here is an example code snippet:
list_With_Duplicates = ['s', 't', 'u', 'f', 'w', 'x', 'y', 'y']
list_Without_Duplicates = list(dict.fromkeys(list_With_Duplicates))
print(list_Without_Duplicates)
#Output is ['s', 't', 'u', 'f', 'w', 'x', 'y']
CodePudding user response:
You can use the remove()
method of the list to remove a specific element by its value. For example:
output = ['s', 't', 'u', 'f', 'w', 'x', 'y', 'y']
output.remove('y')
print(output)