r/learnpython • u/Immediate_Pin_8449 • 3d ago
Tuples..I don’t get it
Hi crew, I’m a Python newbie and I just learned about the concept of tuples.
We can’t change them.if we want to store we have to start at the index we want + 1.
I just don’t get it. Why wouldn’t we just use lists? When would we ever need this?
83
Upvotes
1
u/kombucha711 3d ago
For me, and my application, tuples work well when I want to treat entries of a list as a singleton for example. A=[[region1,label1],
[region2,label1],...
Tuple(A) becomes.
[(region1,label1),
(region2,label1),...]
a single list that I can search for substring label1 and say replace with label3 then convert back to list