Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #53019

Re: Checking homogeneity of Array using List in Python

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 <joshua.landau.ws@gmail.com>
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 <b814mdF7v9aU1@mid.individual.net>
References <39cf54bd-3772-448a-a56e-74e0b3cc8017@googlegroups.com> <b814mdF7v9aU1@mid.individual.net>
From Joshua Landau <joshua@landau.ws>
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 <python-list@python.org>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.248.1377556789.19984.python-list@python.org> (permalink)
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

Show key headers only | View raw


On 26 August 2013 14:49, Neil Cerutti <neilc@norwich.edu> wrote:
> On 2013-08-25, sahil301290@gmail.com <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]

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Checking homogeneity of Array using List in Python sahil301290@gmail.com - 2013-08-24 22:50 -0700
  Re: Checking homogeneity of Array using List in Python Chris Angelico <rosuav@gmail.com> - 2013-08-25 16:03 +1000
  Re: Checking homogeneity of Array using List in Python Joel Goldstick <joel.goldstick@gmail.com> - 2013-08-25 11:54 -0400
  Re: Checking homogeneity of Array using List in Python Dave Angel <davea@davea.name> - 2013-08-25 20:49 +0000
  Re: Checking homogeneity of Array using List in Python Neil Cerutti <neilc@norwich.edu> - 2013-08-26 13:49 +0000
    Re: Checking homogeneity of Array using List in Python Joshua Landau <joshua@landau.ws> - 2013-08-26 23:39 +0100
      Re: Checking homogeneity of Array using List in Python Neil Cerutti <neilc@norwich.edu> - 2013-08-27 12:03 +0000

csiph-web