Python: Mutable tuple? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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!

2nd Sep 2017, 12:16 AM
Andreas Marek (zehnzwanzig)
Andreas Marek (zehnzwanzig) - avatar
5 Answers
+ 3
yes, set is mutable and will only retain unique values
2nd Sep 2017, 12:22 AM
Goran B
Goran B - avatar
+ 3
You can see more here about that https://docs.python.org/2/library/sets.html
2nd Sep 2017, 3:31 AM
Oscar Albornoz
Oscar Albornoz - avatar
+ 1
Omg, I actually forgot about set. Thank you very much :-)
2nd Sep 2017, 3:32 AM
Andreas Marek (zehnzwanzig)
Andreas Marek (zehnzwanzig) - avatar
+ 1
b={1,2,4,5,4,3,6,7,7,8} print(b) output--> {1,2,4,5,3,6,7,8}
2nd Sep 2017, 12:53 PM
sayan chandra
sayan chandra - avatar
+ 1
Here is my primer on tuples in Python - hope you find it useful! https://code.sololearn.com/cce88fWlK7L7/?ref=app
26th Apr 2018, 6:29 PM
Johannes
Johannes - avatar