Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #66917
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Subject | Re: Can tuples be replaced with lists all the time? |
| Date | 2014-02-23 15:49 +1100 |
| References | <64af70e3-6876-4fbf-8386-330d2f48735a@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.7274.1393130974.18130.python-list@python.org> (permalink) |
Sam <lightaiyee@gmail.com> writes: > My understanding of Python tuples is that they are like immutable > lists. That's a common expression, but I think it's not a helpful way to think of them. Rather, the different sequence types have different semantic purposes: * For representing a sequence where each item means exactly the same no matter which position it's in (a “homogeneous sequence”), use a list. * For representing a sequence where the meaning of each item is strongly dependent on its position in the sequence (a “heterogeneous sequence”), use a tuple. See <URL:http://docs.python.org/3/library/stdtypes.html> for the official Python description of the type differences. > If this is the cause, why can't we replace tuples with lists all the > time (just don't reassign the lists)? Correct me if I am wrong. Because we need to represent different semantic concepts in our code, and have each type support the semantics with different operations. -- \ “I went camping and borrowed a circus tent by mistake. I didn't | `\ notice until I got it set up. People complained because they | _o__) couldn't see the lake.” —Steven Wright | Ben Finney
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Can tuples be replaced with lists all the time? Sam <lightaiyee@gmail.com> - 2014-02-22 20:06 -0800
Re: Can tuples be replaced with lists all the time? Paul Rubin <no.email@nospam.invalid> - 2014-02-22 20:28 -0800
Re: Can tuples be replaced with lists all the time? Chris Angelico <rosuav@gmail.com> - 2014-02-23 15:18 +1100
Re: Can tuples be replaced with lists all the time? Ben Finney <ben+python@benfinney.id.au> - 2014-02-23 15:49 +1100
Re: Can tuples be replaced with lists all the time? 88888 Dihedral <dihedral88888@gmail.com> - 2014-02-23 11:45 -0800
Re: Can tuples be replaced with lists all the time? Roy Smith <roy@panix.com> - 2014-02-22 23:19 -0500
Re: Can tuples be replaced with lists all the time? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-03-02 17:21 -0500
Re: Can tuples be replaced with lists all the time? Grant Edwards <invalid@invalid.invalid> - 2014-02-23 17:07 +0000
Re: Can tuples be replaced with lists all the time? Roy Smith <roy@panix.com> - 2014-02-23 12:48 -0500
Re: Can tuples be replaced with lists all the time? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-01 21:20 +0000
Re: Can tuples be replaced with lists all the time? Terry Reedy <tjreedy@udel.edu> - 2014-03-01 18:15 -0500
csiph-web