You can follow these steps to print all the unique values in a list in Python:
Here's the code:
main.py108 chars4 lines
In the code above, the set()
function will create a set with only the unique values from the list, and the list()
function will convert this set into a new list with only unique values.
Output:
main.py25 chars2 lines
Alternatively, you can use a for loop and a conditional statement to check for duplicates and print only unique values:
main.py183 chars9 lines
Output:
main.py25 chars2 lines
Both options will produce the same output, but the first one is more concise and efficient.
gistlibby LogSnag