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: 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>': 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>': 0.20; 'context.': 0.22; '>': 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: References: Date: Sat, 23 Feb 2013 10:11:04 +0100 Subject: Re: Number validation issue From: Morten Engvoldsen 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 --f46d043c084afdcdae04d660afcf Content-Type: text/plain; charset=ISO-8859-1 > > 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 > 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 > To: Python > 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 > 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? > > > --f46d043c084afdcdae04d660afcf Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Hi,
=A0Yes= true, i need to generate weight at run time rather than hard coding it,
following are some solution:
=A0
Since the max len= gth of thenumber should be 25 and minimum should be 2 so code will be in th= is way:
=A0
def is_valid_isbn13(isbn13):
=A0=A0=A0 i= f not len(checknum) >=3D 2 and len(checknum) <=3D25:
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return False
=A0=A0=A0 weigth =3D '= ;1' + ''.join(map(str,range(2,8))*4)
=A0=A0=A0 ex_weigth =3D= list(reversed(list(weigth)[: int(len(isbn13))]))
=A0=A0=A0 return (sum(= int(w) * int(x) for w, x in zip(list(ex_weigth), list(isbn13))) % 11 =3D=3D= 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.
=A0
=A0
=A0
=A0
=A0
=A0
=A0
=A0

---------- 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 Engv= oldsen wrote:
Hi,
Just to make it more clear: I am looking for how to generate the wei= ght in :
1, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7, 2, 3, 4, 5, 6, 7.. form= at for any
length of number instead of

weights =3D [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.

zi= p() 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 pro= blem.


--
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 valida= tion issue
On Fri, Feb 22, 2013 at 11:27 AM, Morten Engvoldsen
<mortenengv@gmail.co= m> wrote:
> Hi,
> Just to make it more clear: I am looking for how to genera= te 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 =3D [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 chec= k that number. Hope, this makes clear
> what i am looking for...

It sounds like you probably should gen= erate the list of weights at
run-time rather than hard-coding it as a li= teral. Have you tried
this?



--f46d043c084afdcdae04d660afcf--