Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #53056
| From | Neil Cerutti <neilc@norwich.edu> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Checking homogeneity of Array using List in Python |
| Date | 2013-08-27 12:03 +0000 |
| Organization | Norwich University |
| Message-ID | <b83isaFod5aU1@mid.individual.net> (permalink) |
| References | <39cf54bd-3772-448a-a56e-74e0b3cc8017@googlegroups.com> <b814mdF7v9aU1@mid.individual.net> <mailman.248.1377556789.19984.python-list@python.org> |
On 2013-08-26, Joshua Landau <joshua@landau.ws> wrote:
> 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]
Very nice! It seems like unlucky students sometimes get C
programming courses ham-fisted into Python without much thought.
--
Neil Cerutti
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll 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