Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'python': 0.09; 'immutable': 0.09; 'lawrence': 0.09; 'porting': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'sep': 0.09; 'spelling': 0.09; "wouldn't": 0.11; 'dictionaries': 0.16; 'dimension': 0.16; 'pair,': 0.16; 'perfect.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'recipes': 0.16; 'singleton': 0.16; 'subject:Java': 0.16; 'wrote:': 0.17; 'java': 0.21; "i've": 0.23; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'wondering': 0.26; 'library.': 0.27; 'header:X-Complaints-To:1': 0.28; 'loads': 0.29; 'thinks': 0.29; 'case,': 0.29; "i'm": 0.29; 'usually': 0.30; 'code': 0.31; 'from:addr:yahoo.co.uk': 0.32; 'to:addr:python- list': 0.33; 'pm,': 0.35; 'there': 0.35; 'received:org': 0.36; 'why': 0.37; 'subject:: ': 0.38; 'mark': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'called': 0.39; 'header:Received:5': 0.40; 'think': 0.40; 'containing': 0.61; 'map': 0.61; 'fun': 0.64; "(don't": 0.84; 'received:2': 0.91; 'fight': 0.97 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: Java singletonMap in Python Date: Mon, 24 Sep 2012 20:44:25 +0100 References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-2-100-238-176.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.0; rv:15.0) Gecko/20120907 Thunderbird/15.0.1 In-Reply-To: X-Antivirus: avast! (VPS 120924-0, 24/09/2012), Outbound message X-Antivirus-Status: Clean X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1348515819 news.xs4all.nl 6856 [2001:888:2000:d::a6]:36998 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:29923 On 24/09/2012 20:22, Devin Jeanpierre wrote: > On Sun, Sep 23, 2012 at 7:14 PM, Mark Lawrence wrote: >> Purely for fun I've been porting some code to Python and came across the >> singletonMap[1]. I'm aware that there are loads of recipes on the web for >> both singletons e.g.[2] and immutable dictionaries e.g.[3]. I was wondering >> how to combine any of the recipes to produce the best implementation > > The word "singleton" usually means "thing with only one item". For > example, {a} is a singleton set containing only a, and with matrices, > any dimension of size one is called a singleton dimension, and so on. > In this case, a singleton map is a map with only one key-value pair, > such as {a:b}. > > The singleton design antipattern is not relevant here. > > -- Devin > Java thinks so otherwise there wouldn't also be the singleton which is the spelling for singletonSet (don't ask me!!!) and a singletonList. From the Python viewpoint I think YAGNI is perfect. I now understand why the BDFL and others fight so hard to keep bloatware out of the standard library. -- Cheers. Mark Lawrence.