Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Ben Finney Newsgroups: comp.lang.python Subject: Re: Late-binding of function defaults (was Re: What is a function parameter =[] for?) Date: Thu, 26 Nov 2015 06:55:24 +1100 Lines: 38 Message-ID: References: <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> <878u5mns8z.fsf@elektro.pacujo.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de puV7eBMR8N3zreQmGWiS8wPtgWixeHOsUVUq9cv9GwQA== Cancel-Lock: sha1:Dm2MGOCAi2a+OWNK8kbsKB7cK6M= Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'tuple': 0.09; 'way:': 0.09; '(2,': 0.16; '(3,': 0.16; '[2,': 0.16; 'distinction': 0.16; 'immutability': 0.16; 'mutability': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'subject:?)': 0.16; 'tuple,': 0.16; 'tuple;': 0.16; 'basically': 0.18; 'element': 0.18; 'instance,': 0.18; '(in': 0.18; 'language': 0.19; 'not,': 0.22; 'saying': 0.22; 'tuples': 0.22; 'header:User-Agent:1': 0.26; 'header:X-Complaints- To:1': 0.26; 'chris': 0.26; 'sequence': 0.27; 'tend': 0.27; 'becomes': 0.30; 'putting': 0.30; 'regardless': 0.31; 'another': 0.32; 'generally': 0.32; 'align': 0.33; 'items.': 0.33; '(for': 0.34; 'lists': 0.34; 'list': 0.34; 'gives': 0.35; 'growing': 0.35; 'something': 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'received:org': 0.37; 'list.': 0.37; 'things': 0.38; 'wrong': 0.38; 'mean': 0.38; 'means': 0.39; 'does': 0.39; 'subject:-': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'still': 0.40; 'more': 0.63; 'different': 0.63; 'fact,': 0.67; '8bit%:21': 0.70; 'skip:\xe2 10': 0.70; 'grow': 0.75; '_o__)': 0.84; 'enforces': 0.84; 'fifty': 0.84; 'received:125': 0.84; 'shopping': 0.87; 'louis': 0.93 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: jigong.madmonks.org X-Public-Key-ID: 0xAC128405 X-Public-Key-Fingerprint: 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-pubkey.asc X-Post-From: Ben Finney User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:99480 Chris Angelico writes: > This is a distinction I generally make. Putting it another way: a list > has the same meaning regardless of how many items are on it (for > instance, a shopping list is still a shopping list whether it has five > or fifty items on it), where a tuple is a package where each element > has a specific meaning […] Yes. The disctinction is even clearer, I find, by saying that the *meaning of the position* in the sequence is significant for a tuple, not significant for a list. That is, the ‘2’ in ‘cartesian_point = (2, 3)’ means something different than in ‘cartesian_point = (3, 2)’. Whereas the ‘2’ in ‘test_scores = [2, 3]’ means exactly the same as in ‘test_scores = [3, 2]’. If each position in the sequence gives the value there a different menaning, use a tuple; if not, use a list. > Nothing in the language enforces this, but the mutability of lists > does tend to align well with things that can grow and shrink, and the > immutability of tuples makes them more like strings or complex numbers > (in fact, a complex number is basically a tuple of two floats). Not only the growing and shrinking, but the re-ordering of items in a list should not change the meaning of its items. If you can ‘sort’ the sequence and the items still mean exactly what they did before, then a tuple is the wrong type to use, semantically. -- \ “Crime is contagious… if the government becomes a lawbreaker, | `\ it breeds contempt for the law.” —Justice Louis Brandeis | _o__) | Ben Finney