Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed4.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.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'subject:Python': 0.06; '[1,': 0.09; 'interpreted': 0.09; 'subject:using': 0.09; 'try:': 0.09; 'used.': 0.09; 'def': 0.12; '[none]': 0.16; 'item:': 0.16; 'think.': 0.16; 'prevent': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'input': 0.22; 'char': 0.24; 'header:In-Reply- To:1': 0.27; 'function': 0.29; 'message-id:@mail.gmail.com': 0.30; "skip:' 10": 0.31; 'keyerror:': 0.31; 'class': 0.32; 'to:name :python-list': 0.33; 'skip:_ 10': 0.34; "can't": 0.35; 'except': 0.35; 'received:google.com': 0.35; 'subject:List': 0.36; 'yield': 0.36; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'august': 0.61; 'email addr:gmail.com': 0.63; 'note:': 0.66; 'as:': 0.81; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:content-type; bh=1X3nY6dpy9PLq7SjGDMFy7Ffx6BDBnWOIau3wkeXzpc=; b=gtQcUTPALMjM+T1HSbHGUlQNWXSh4qCs6KzqEZj0Fmh3eVloHjiS5K5Y8WEMxlESnV 5uqxO6bmxnwrt7HzOKayzAFnYJb1X4I+JD/GYU9MP3BwWUOLCTRcmqbe/eRfkaiZuFoB XH6P7h3kPgU9NKqg+HCaIrd7a2eq4vPXs0LLwTesZYRAJ+niYM+7WD1iWCT+MMgl/j9g xCdM2hLYikKOQ8I6PWLqUJtK9xE3tJTi/kDjPn2Rl6g+t/X6DmdkFxwB0iMUAFOIGyCG ItTiRWeu68n2hW/kJnBsjxC6wgmKAZulN+9F7gXwl1jFbGUjN3b9v8RR240psG5zqNcc lJvw== X-Received: by 10.112.146.33 with SMTP id sz1mr14388307lbb.14.1377556782198; Mon, 26 Aug 2013 15:39:42 -0700 (PDT) MIME-Version: 1.0 Sender: joshua.landau.ws@gmail.com In-Reply-To: References: <39cf54bd-3772-448a-a56e-74e0b3cc8017@googlegroups.com> From: Joshua Landau Date: Mon, 26 Aug 2013 23:39:02 +0100 X-Google-Sender-Auth: 9Ou_p2Rp4pydDnpACVV5EI91qu4 Subject: Re: Checking homogeneity of Array using List in Python To: python-list Content-Type: text/plain; charset=UTF-8 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: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1377556789 news.xs4all.nl 16005 [2001:888:2000:d::a6]:59366 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:53019 On 26 August 2013 14:49, Neil Cerutti wrote: > On 2013-08-25, sahil301290@gmail.com wrote: >> >> eg. my input is ['1', ' ', 'asdasd231231', '1213asasd', '43242'] >> I want it to be interpreted as: >> [1, [None], [None], [None], 43242] >> >> NOTE: NO INBUILT FUNCTION BE USED. > > Impossible. I think. class BoilerplateToStopCheating: def __init__(self): """Factor things out to prevent cheating.""" self.digit_to_number = {"0":0, "1":1, "2":2, "3":3, "4":4, "5":5, "6":6, "7":7, "8":8, "9":9} def __call__(self, items): def fudging(): """More cheat-fudging.""" for item in items: try: as_number = 0 for char in item: as_number *= 10 as_number += self.digit_to_number[char] yield as_number except KeyError: yield [None] [*z] = fudging() return z converter = BoilerplateToStopCheating() # Can't use "print"... # Erm... converter(['1', ' ', 'asdasd231231', '1213asasd', '43242']) # Output: [1, [None], [None], [None], 43242]