Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #9482
| Date | 2011-07-14 20:12 +0100 |
|---|---|
| From | MRAB <python@mrabarnett.plus.com> |
| Subject | Re: Please critique my script |
| References | <77AE044B1BF3944FAE2435F395F11B4B01859CD7@clt-exmb02.bbtnet.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1033.1310670724.1164.python-list@python.org> (permalink) |
[snip]
raw_input() returns a string, so there's no need for these 3 lines:
> y = str(y)
> z = str(z)
> p = str(p)
> pagedef = ("http://www.localcallingguide.com/xmllocalprefix.php?npa="
+ y + "&nxx=" + z)
> print "Querying", pagedef
>
> #------Get info from NANPA.com ----------
> urllib2.install_opener(opener)
> page = urllib2.urlopen(pagedef)
> soup = BeautifulSoup(page)
> soup = str(soup)
>
> #------Parse Gathered Data----------
> for line in npaReg.findall(soup):
> npalist.insert(count, line)
> count = count + 1
>
> for line2 in nxxReg.findall(soup):
> nxxlist.insert(count2, line2)
> count2 = count2 + 1
>
enumerate will help you here:
for count, line in enumerate(npaReg.findall(soup)):
npalist.insert(count, line)
for count2, line2 in enumerate(nxxReg.findall(soup)):
nxxlist.insert(count2, line2)
> #-----Sort, remove duplicates, concatenate the last digits for
similiar NPA/NXX ------
> for makenewlist in range(0, count):
> sortlist.append(npalist.pop(0) + nxxlist.pop(0))
>
> sortlist.sort()
>
> for sortednumber in sortlist:
> if sortednumber not in sortedlist:
> sortedlist.append(sortednumber)
>
If you're going to sort them anyway (so you don't need to preserve the
existing order), the easiest way to remove duplicates is to use a set:
sortedlist = sorted(set(sortlist))
[snip]
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Re: Please critique my script MRAB <python@mrabarnett.plus.com> - 2011-07-14 20:12 +0100
Re: Please critique my script Peter Otten <__peter__@web.de> - 2011-07-14 22:53 +0200
Re: Please critique my script MRAB <python@mrabarnett.plus.com> - 2011-07-14 23:47 +0100
csiph-web