More pythonic way to change an element of a tuple?

Wojtek Walczak gminick at hacker.pl
Wed Nov 27 13:33:46 EST 2002


Dnia Wed, 27 Nov 2002 09:58:44 -0800, Richard Muller napisał(a):
> I frequently have to change a single element of a tuple, and I wind up 
> doing something like this:
> 
> tmp = list(data_in_tuple)
> tmp[item] += 1
> data_in_tuple = tuple(tmp)
> 
> Is there a more beautiful way of doing this? 
You should use lists instead. When I'm seeing a tuple in someones else
code I'm assuming, that values in tuples are constants. It isn't nice
practise to change their values.

-- 
[ ] gminick (at) underground.org.pl  http://gminick.linuxsecurity.pl/ [ ]
[ "Po prostu lubie poranna samotnosc, bo wtedy kawa smakuje najlepiej." ]



More information about the Python-list mailing list