0
Python: Mutable tuple?
Hey Sololearn! So, we got this 2 datatypes: List and Tuple. A list is mutable, a tuple isn't. But every item in a tuple is unique. Is there a datatype, that is mutable, but their items have to be unique (like in a tuple)? Or do I have to go the long way and sort those items out of list the list by myself? Thanks in advance!
5 Respuestas
+ 3
yes, set is mutable and will only retain unique values
+ 3
You can see more here about that
https://docs.python.org/2/library/sets.html
+ 1
Omg, I actually forgot about set. Thank you very much :-)
+ 1
b={1,2,4,5,4,3,6,7,7,8}
print(b)
output-->
{1,2,4,5,3,6,7,8}
+ 1
Here is my primer on tuples in Python - hope you find it useful!
https://code.sololearn.com/cce88fWlK7L7/?ref=app