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


Groups > comp.lang.python > #39651

Re: Number validation issue

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder3.xlned.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <mortenengv@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'true,': 0.04; 'run-time': 0.05; '-0500': 0.07; 'stops': 0.07; 'python': 0.09; '22,': 0.09; 'way:': 0.09; 'email addr:python.org&gt;': 0.10; 'def': 0.10; "skip:' 30": 0.15; 'int(x)': 0.16; 'literal.': 0.16; 'losing': 0.16; 'subject:issue': 0.16; 'wrote:': 0.17; 'feb': 0.19; 'email addr:gmail.com&gt;': 0.20; 'context.': 0.22; '&gt;': 0.23; 'cc:2**1': 0.24; 'tried': 0.25; 'header:In-Reply-To:1': 0.25; '----------': 0.26; 'am,': 0.27; 'cc:addr:gmail.com': 0.27; 'coding': 0.27; 'message-id:@mail.gmail.com': 0.27; 'fixed': 0.28; 'this?': 0.28; 'fine': 0.28; 'run': 0.28; 'date:': 0.29; 'probably': 0.29; 'fri,': 0.30; 'code': 0.31; 'problem.': 0.32; 'received:74.125.82': 0.33; 'shorter': 0.33; 'subject:Number': 0.33; 'to:addr:python-list': 0.33; 'hi,': 0.33; 'received:google.com': 0.34; 'minimum': 0.34; 'list': 0.35; 'clear': 0.35; 'false': 0.35; 'pm,': 0.35; 'there': 0.35; 'subject:': 0.36; 'received:74.125': 0.36; 'email addr:python.org': 0.36; 'should': 0.36; 'two': 0.37; 'rather': 0.37; 'subject:: ': 0.38; 'from:': 0.38; 'skip:l 20': 0.38; 'some': 0.38; 'forwarded': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'your': 0.60; 'email name:python- list': 0.62; 'repeat': 0.62; 'solve': 0.62; 'provide': 0.62; 'between': 0.63; 'more': 0.63; 'sounds': 0.71; '2013': 0.84; '\xa0\xa0\xa0\xa0\xa0': 0.84; '\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0': 0.84; 'angel': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=sd2cMltP5kYpH2wDk481yiKyhQebhD0psYf+tJA7NfY=; b=sc6PvfvwgCXoeuWriRUh1HiSGc+xqbFd3R3n1/Y4x3C5RoYwlg0eQRc62BjPADsB61 y9DQaIX2VXsnql7PWmZ5zz/KfUP/J/qyyjnB+VlTuLXd6XITLG+/w175kj6rDSGAveft kj4/T3xivEfko6ovIBExkay3FdcdHrWp9mbPcEQrZRpoHM3WXZApbqDbqeZYKW6Gh1Q8 AEXU1GBm5lOooVftroIvb8Kvjn29KQucqjkyMfCOCjruzLPBZrQol2h5HRKQTYf51Tk9 wHEABmGOzQGlmXYTsm9LoFTNKIYxF2XJIFuzucFyKs4/k1A++DLNmzmT9WklhLR+aNZw 01aQ==
MIME-Version 1.0
X-Received by 10.181.11.198 with SMTP id ek6mr2524645wid.1.1361610664690; Sat, 23 Feb 2013 01:11:04 -0800 (PST)
In-Reply-To <CAJ2vgs5_gYPvMxfBUjs_6QgzUNd4akTvL2p0jV+7E-m8_6xeUw@mail.gmail.com>
References <CAJ2vgs5_gYPvMxfBUjs_6QgzUNd4akTvL2p0jV+7E-m8_6xeUw@mail.gmail.com>
Date Sat, 23 Feb 2013 10:11:04 +0100
Subject Re: Number validation issue
From Morten Engvoldsen <mortenengv@gmail.com>
To python-list@python.org
Content-Type multipart/alternative; boundary=f46d043c084afdcdae04d660afcf
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.2330.1361610672.2939.python-list@python.org> (permalink)
Lines 177
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1361610672 news.xs4all.nl 6948 [2001:888:2000:d::a6]:58476
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:39651

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

>
> Hi,
>
 Yes true, i need to generate weight at run time rather than hard coding it,
following are some solution:

Since the max length of thenumber should be 25 and minimum should be 2 so
code will be in this way:

def is_valid_isbn13(isbn13):
    if not len(checknum) >= 2 and len(checknum) <=25:
            return False
    weigth = '1' + ''.join(map(str,range(2,8))*4)
    ex_weigth = list(reversed(list(weigth)[: int(len(isbn13))]))
    return (sum(int(w) * int(x) for w, x in zip(list(ex_weigth),
list(isbn13))) % 11 == 0)

is_valid_isbn13("123456785")

This code works fine for any length of digit between 2 to 25, this is what
exactly i need, is there any other better approch you have to generate the
weight at run time.









>
> ---------- Forwarded message ----------
> From: Dave Angel <davea@davea.name>
> To: python-list@python.org
> Cc:
> Date: Fri, 22 Feb 2013 13:45:30 -0500
> Subject: Re: Number validation issue
> On 02/22/2013 01:27 PM, Morten Engvoldsen wrote:
>
>> Hi,
>> Just to make it more clear: I am looking for how to generate the weight
>> in :
>> 1, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7.. format for any
>> length of number instead of
>>
>> weights = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1]
>>
>> only for fixed digit.
>>
>> My below code can check only for 9 digit, so if we provide a number of
>> more
>> than 9 digit, it is not able to check that number. Hope, this makes clear
>> what i am looking for...
>>
>> You keep top-posting, so we keep losing the context.
>
> zip() stops at the shorter of the two iterables. And itertools.cycle()
> will repeat a list infinitely. The two of them should be able to solve your
> problem.
>
>
> --
> DaveA
>
>
>
> ---------- Forwarded message ----------
> From: Ian Kelly <ian.g.kelly@gmail.com>
> To: Python <python-list@python.org>
> Cc:
> Date: Fri, 22 Feb 2013 11:50:13 -0700
> Subject: Re: Number validation issue
> On Fri, Feb 22, 2013 at 11:27 AM, Morten Engvoldsen
> <mortenengv@gmail.com> wrote:
> > Hi,
> > Just to make it more clear: I am looking for how to generate the weight
> in :
> > 1, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7.. format for any
> > length of number instead of
> >
> > weights = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1]
> >
> > only for fixed digit.
> >
> > My below code can check only for 9 digit, so if we provide a number of
> more
> > than 9 digit, it is not able to check that number. Hope, this makes clear
> > what i am looking for...
>
> It sounds like you probably should generate the list of weights at
> run-time rather than hard-coding it as a literal. Have you tried
> this?
>
>
>

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


Thread

Re: Number validation issue Morten Engvoldsen <mortenengv@gmail.com> - 2013-02-23 10:11 +0100

csiph-web