Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #79469 > unrolled thread
| Started by | Seymore4Head <Seymore4Head@Hotmail.invalid> |
|---|---|
| First post | 2014-10-22 16:30 -0400 |
| Last post | 2014-10-25 22:15 +0000 |
| Articles | 20 on this page of 157 — 23 participants |
Back to article view | Back to comp.lang.python
I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-22 16:30 -0400
Re: I am out of trial and error again Lists Joel Goldstick <joel.goldstick@gmail.com> - 2014-10-22 16:57 -0400
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-22 17:04 -0400
Re: I am out of trial and error again Lists sohcahtoa82@gmail.com - 2014-10-22 14:35 -0700
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-22 17:38 -0400
Re: I am out of trial and error again Lists Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-22 22:28 +0100
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-22 18:30 -0400
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-22 18:32 -0400
Re: I am out of trial and error again Lists Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-22 23:55 +0100
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-22 19:26 -0400
Re: I am out of trial and error again Lists Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-23 00:44 +0100
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-22 20:02 -0400
Re: I am out of trial and error again Lists MRAB <python@mrabarnett.plus.com> - 2014-10-23 02:29 +0100
Re: I am out of trial and error again Lists alex23 <wuwei23@gmail.com> - 2014-10-23 11:37 +1000
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-22 21:52 -0400
Re: I am out of trial and error again Lists Larry Hudson <orgnut@yahoo.com> - 2014-10-22 19:58 -0700
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-22 23:05 -0400
Re: I am out of trial and error again Lists Rustom Mody <rustompmody@gmail.com> - 2014-10-22 20:16 -0700
Re: I am out of trial and error again Lists Terry Reedy <tjreedy@udel.edu> - 2014-10-23 02:31 -0400
Re: I am out of trial and error again Lists MRAB <python@mrabarnett.plus.com> - 2014-10-23 00:09 +0100
Re: I am out of trial and error again Lists Larry Hudson <orgnut@yahoo.com> - 2014-10-23 00:10 -0700
Re: I am out of trial and error again Lists Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-23 09:23 -0400
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-23 10:00 -0400
Re: I am out of trial and error again Lists Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-23 20:23 -0400
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-23 09:53 -0400
Re: I am out of trial and error again Lists Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-23 09:15 +0000
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-23 10:04 -0400
Re: I am out of trial and error again Lists Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-23 15:55 +0000
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-23 13:01 -0400
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-23 13:07 -0400
Re: I am out of trial and error again Lists Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-23 13:39 -0600
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-23 16:15 -0400
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-23 16:44 -0400
Re: I am out of trial and error again Lists MRAB <python@mrabarnett.plus.com> - 2014-10-23 22:03 +0100
Re: I am out of trial and error again Lists Larry Hudson <orgnut@yahoo.com> - 2014-10-23 19:13 -0700
Re: I am out of trial and error again Lists Terry Reedy <tjreedy@udel.edu> - 2014-10-23 23:14 -0400
Re: I am out of trial and error again Lists Chris Angelico <rosuav@gmail.com> - 2014-10-24 14:32 +1100
Re: I am out of trial and error again Lists Rustom Mody <rustompmody@gmail.com> - 2014-10-23 21:56 -0700
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-24 10:38 -0400
Re: I am out of trial and error again Lists Chris Angelico <rosuav@gmail.com> - 2014-10-25 01:51 +1100
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-24 11:04 -0400
Re: I am out of trial and error again Lists Chris Angelico <rosuav@gmail.com> - 2014-10-25 02:13 +1100
Re: I am out of trial and error again Lists Rustom Mody <rustompmody@gmail.com> - 2014-10-24 08:56 -0700
Re: I am out of trial and error again Lists Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-24 10:35 -0600
Re: I am out of trial and error again Lists Rustom Mody <rustompmody@gmail.com> - 2014-10-24 10:10 -0700
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-24 12:37 -0400
Re: I am out of trial and error again Lists Chris Angelico <rosuav@gmail.com> - 2014-10-25 03:47 +1100
Re: I am out of trial and error again Lists Rustom Mody <rustompmody@gmail.com> - 2014-10-24 09:56 -0700
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-24 13:03 -0400
Re: I am out of trial and error again Lists "Albert Visser" <albert.visser@gmail.com> - 2014-10-24 19:18 +0200
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-24 13:23 -0400
Re: I am out of trial and error again Lists Rustom Mody <rustompmody@gmail.com> - 2014-10-24 10:42 -0700
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-24 13:42 -0400
Re: I am out of trial and error again Lists Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-24 11:52 -0600
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-24 14:15 -0400
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-24 14:20 -0400
Re: I am out of trial and error again Lists Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-24 19:40 +0100
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-24 15:07 -0400
Re: I am out of trial and error again Lists Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-24 21:49 +0000
Re: I am out of trial and error again Lists Larry Hudson <orgnut@yahoo.com> - 2014-10-24 23:46 -0700
Re: I am out of trial and error again Lists Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-25 08:17 -0600
Re: I am out of trial and error again Lists Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-25 14:47 -0400
Re: I am out of trial and error again Lists sohcahtoa82@gmail.com - 2014-10-24 11:57 -0700
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-24 15:09 -0400
Re: I am out of trial and error again Lists sohcahtoa82@gmail.com - 2014-10-24 12:25 -0700
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-24 15:33 -0400
Re: I am out of trial and error again Lists sohcahtoa82@gmail.com - 2014-10-24 12:55 -0700
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-24 16:00 -0400
Re: I am out of trial and error again Lists Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-24 21:19 +0000
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-24 17:35 -0400
Re: I am out of trial and error again Lists Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-24 23:23 +0000
Re: I am out of trial and error again Lists Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-25 14:37 -0400
Re: I am out of trial and error again Lists Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-24 19:33 +0100
Re: I am out of trial and error again Lists Rustom Mody <rustompmody@gmail.com> - 2014-10-24 09:54 -0700
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-24 13:04 -0400
Re: I am out of trial and error again Lists Rustom Mody <rustompmody@gmail.com> - 2014-10-24 10:17 -0700
Re: I am out of trial and error again Lists Dave Angel <davea@davea.name> - 2014-10-24 18:09 -0400
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-24 18:27 -0400
Re: I am out of trial and error again Lists Rustom Mody <rustompmody@gmail.com> - 2014-10-24 16:01 -0700
Re: I am out of trial and error again Lists Terry Reedy <tjreedy@udel.edu> - 2014-10-24 20:27 -0400
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-24 20:42 -0400
Re: I am out of trial and error again Lists Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-24 11:05 -0600
Re: I am out of trial and error again Lists Chris Angelico <rosuav@gmail.com> - 2014-10-25 04:10 +1100
Re: I am out of trial and error again Lists Larry Hudson <orgnut@yahoo.com> - 2014-10-24 23:04 -0700
Re: I am out of trial and error again Lists Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-24 20:37 +0000
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-24 16:58 -0400
Re: I am out of trial and error again Lists alister <alister.nospam.ware@ntlworld.com> - 2014-10-24 21:07 +0000
Re: I am out of trial and error again Lists Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-24 15:11 -0600
Re: I am out of trial and error again Lists Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-24 23:21 +0000
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-24 19:48 -0400
Re: I am out of trial and error again Lists Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-24 21:48 +0000
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-24 18:14 -0400
Re: I am out of trial and error again Lists Grant Edwards <invalid@invalid.invalid> - 2014-10-25 15:01 +0000
Re: I am out of trial and error again Lists Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-25 20:51 +0000
Re: I am out of trial and error again Lists Larry Hudson <orgnut@yahoo.com> - 2014-10-24 19:16 -0700
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-24 22:41 -0400
Re: I am out of trial and error again Lists Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-25 08:25 +0100
Re: I am out of trial and error again Lists Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-25 15:10 -0400
Re: I am out of trial and error again Lists Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-25 14:23 -0400
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-25 14:42 -0400
Re: I am out of trial and error again Lists Terry Reedy <tjreedy@udel.edu> - 2014-10-25 18:48 -0400
Re: I am out of trial and error again Lists Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-26 00:25 +0100
Re: I am out of trial and error again Lists Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-26 01:08 -0400
Re: I am out of trial and error again Lists Terry Reedy <tjreedy@udel.edu> - 2014-10-26 17:44 -0400
Re: I am out of trial and error again Lists Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-10-26 20:57 -0400
Re: I am out of trial and error again Lists Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-22 22:43 +0000
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-22 19:11 -0400
The “trials” in “trial and error” should be as simple as possible (was: I am out of trial and error again Lists) Ben Finney <ben+python@benfinney.id.au> - 2014-10-23 10:59 +1100
Re: I am out of trial and error again Lists Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-23 11:05 +1100
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-22 20:10 -0400
Re: I am out of trial and error again Lists MRAB <python@mrabarnett.plus.com> - 2014-10-23 02:31 +0100
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-22 21:35 -0400
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-22 21:57 -0400
Re: I am out of trial and error again Lists Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-23 08:20 +0100
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-23 10:01 -0400
Re: I am out of trial and error again Lists Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-23 01:56 -0600
Re: I am out of trial and error again Lists Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-23 09:09 +0100
Re: I am out of trial and error again Lists Rustom Mody <rustompmody@gmail.com> - 2014-10-23 06:42 -0700
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-23 10:03 -0400
Re: I am out of trial and error again Lists Rustom Mody <rustompmody@gmail.com> - 2014-10-23 08:35 -0700
Re: I am out of trial and error again Lists giacomo boffi <pecore@pascolo.net> - 2014-10-23 16:25 +0200
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-23 10:29 -0400
Re: I am out of trial and error again Lists Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-23 16:00 +0000
Re: I am out of trial and error again Lists giacomo boffi <pecore@pascolo.net> - 2014-10-23 16:40 +0200
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-23 10:46 -0400
Re: I am out of trial and error again Lists giacomo boffi <pecore@pascolo.net> - 2014-10-24 17:56 +0200
Re: I am out of trial and error again Lists Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-23 09:21 +0000
Re: I am out of trial and error again Lists Tobiah <toby@tobiah.org> - 2014-10-23 07:51 -0700
Re: I am out of trial and error again Lists Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-24 08:05 +0100
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-24 10:47 -0400
Re: I am out of trial and error again Lists mm0fmf <none@mailinator.com> - 2014-10-24 22:06 +0100
Re: I am out of trial and error again Lists Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-24 09:12 +0100
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-24 10:48 -0400
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-24 18:26 -0400
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-24 18:58 -0400
Re: I am out of trial and error again Lists Rustom Mody <rustompmody@gmail.com> - 2014-10-24 16:27 -0700
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-24 19:48 -0400
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-24 19:57 -0400
Re: I am out of trial and error again Lists MRAB <python@mrabarnett.plus.com> - 2014-10-25 01:20 +0100
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-24 20:37 -0400
Re: I am out of trial and error again Lists Cameron Simpson <cs@zip.com.au> - 2014-10-25 11:52 +1100
Re: I am out of trial and error again Lists Rustom Mody <rustompmody@gmail.com> - 2014-10-24 20:46 -0700
Re: I am out of trial and error again Lists Rustom Mody <rustompmody@gmail.com> - 2014-10-24 21:09 -0700
Re: I am out of trial and error again Lists Ben Finney <ben+python@benfinney.id.au> - 2014-10-25 15:25 +1100
Re: I am out of trial and error again Lists Rustom Mody <rustompmody@gmail.com> - 2014-10-24 22:40 -0700
Re: I am out of trial and error again Lists Chris Angelico <rosuav@gmail.com> - 2014-10-25 16:49 +1100
Re: I am out of trial and error again Lists Rustom Mody <rustompmody@gmail.com> - 2014-10-24 22:55 -0700
Re: I am out of trial and error again Lists Chris Angelico <rosuav@gmail.com> - 2014-10-25 17:03 +1100
Re: I am out of trial and error again Lists Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-25 18:44 +1100
Re: I am out of trial and error again Lists Rustom Mody <rustompmody@gmail.com> - 2014-10-25 10:24 -0700
Side-effects [was Re: I am out of trial and error again Lists] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-26 17:12 +1100
Re: Side-effects [was Re: I am out of trial and error again Lists] Chris Angelico <rosuav@gmail.com> - 2014-10-26 17:42 +1100
Re: I am out of trial and error again Lists giacomo boffi <pecore@pascolo.net> - 2014-10-27 22:26 +0100
Re: I am out of trial and error again Lists Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-25 00:27 +0100
Re: I am out of trial and error again Lists Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-24 23:35 +0000
Re: I am out of trial and error again Lists Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-10-24 20:15 -0400
Re: I am out of trial and error again Lists Denis McMahon <denismfmcmahon@gmail.com> - 2014-10-25 22:15 +0000
Page 2 of 8 — ← Prev page 1 [2] 3 4 5 6 7 8 Next page →
| From | Larry Hudson <orgnut@yahoo.com> |
|---|---|
| Date | 2014-10-23 00:10 -0700 |
| Message-ID | <PdOdnbp2sal5NNXJnZ2dnUU7-KudnZ2d@giganews.com> |
| In reply to | #79475 |
On 10/22/2014 03:30 PM, Seymore4Head wrote:
> On Wed, 22 Oct 2014 16:30:37 -0400, Seymore4Head
> <Seymore4Head@Hotmail.invalid> wrote:
>
> One more question.
> if y in str(range(10)
> Why doesn't that work.
> I commented it out and just did it "long hand"
>
> def nametonumber(name):
> lst=[]
> nx=[]
> for x in (name):
> lst.append(x)
> for y in (lst):
> #if y in str(range(10)):
> if y in "1234567890":
> nx.append(y)
> if y in " -()":
> nx.append(y)
> if y in "abc":
> nx.append("2")
> if y in "def":
> nx.append("3")
> if y in "ghi":
> nx.append("4")
> if y in "jkl":
> nx.append("5")
> if y in "mno":
> nx.append("6")
> if y in "pqrs":
> nx.append("7")
> if y in "tuv":
> nx.append("8")
> if y in "wxyz":
> nx.append("9")
> number="".join(str(e) for e in nx)
> return (number)
> a="1-800-getcharter"
> print (nametonumber(a))#1800 438 2427 837
> a="1-800-leo laporte"
> print (nametonumber(a))
> a="1 800 callaprogrammer"
> print (nametonumber(a))
>
I know you are trying to explore lists here, but I found myself somewhat intrigued with the
problem itself, so I wrote a different version. This version does not use lists but only
strings. I'm just presenting it as-is to let you try to follow the logic, but if you ask, I'll
explain it in detail. It turns your long sequence of if's essentially into a single line --
unfortunately 's' and 'z' have to be handled as special-cases, which turns that single line into
a six-line if/elif/else set. You might consider this line 'tricky', but I'll just say it's just
looking at the problem from a different viewpoint. BTW, this version accepts upper-case as well
as lower-case. isdigit() and isalpha() are standard string methods.
#------ Code ----------
def name2number(name):
nstr = '' # Phone-number string to return
codes = 'abcdefghijklmnopqrtuvwxy' # Note missing s and z
for ch in name:
if ch in " -()":
nstr += ch
elif ch.isdigit():
nstr += ch
elif ch.isalpha():
ch = ch.lower()
# S and Z are special cases
if ch == 's':
nstr += '7'
elif ch == 'z':
nstr += '9'
else:
nstr += str(codes.index(ch) // 3 + 2)
return nstr
#------- End of Code ---------
A possible variation would be to make nstr a list instead of a string, and use .append() instead
of the +=, and finally return the string by using join() on the list. Also, the if and first
elif in the for could be combined: if ch in " -()" or ch.isdigit():
-=- Larry -=-
[toc] | [prev] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2014-10-23 09:23 -0400 |
| Message-ID | <mailman.15108.1414070619.18130.python-list@python.org> |
| In reply to | #79503 |
On Thu, 23 Oct 2014 00:10:28 -0700, Larry Hudson
<orgnut@yahoo.com.dmarc.invalid> declaimed the following:
>I know you are trying to explore lists here, but I found myself somewhat intrigued with the
>problem itself, so I wrote a different version. This version does not use lists but only
>strings. I'm just presenting it as-is to let you try to follow the logic, but if you ask, I'll
>explain it in detail. It turns your long sequence of if's essentially into a single line --
>unfortunately 's' and 'z' have to be handled as special-cases, which turns that single line into
>a six-line if/elif/else set. You might consider this line 'tricky', but I'll just say it's just
>looking at the problem from a different viewpoint. BTW, this version accepts upper-case as well
>as lower-case. isdigit() and isalpha() are standard string methods.
>
<SNIP>
This is another example where changing data structures can simplify
things a lot...
-=-=-=-=-=-=-
keys = { "a" : "2", "b" : "2", "c" : "2", # 1 is not assigned
"d" : "3", "e" : "3", "f" : "3",
"g" : "4", "h" : "4", "i" : "4",
"j" : "5", "k" : "5", "l" : "5",
"m" : "6", "n" : "6", "o" : "6",
"p" : "7", "q" : "7", "r" : "7", "s" : "7",
"t" : "8", "u" : "8", "v" : "8",
"w" : "9", "x" : "9", "y" : "9", "z" : "9" }
def textToNumber(inp):
outp = []
for c in inp.lower():
outp.append(keys.get(c, c))
return "".join(outp)
if __name__ == "__main__":
while True:
#NOTE: Python 2.7!
aNumStr = raw_input("\nEnter Phone Number String: ")
if not aNumStr: break
print "Converted to all numbers: %s" % textToNumber(aNumStr)
-=-=-=-=-=-=-
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\Wulfraed\Documents\Python Progs>Phone.py
Enter Phone Number String: 1-800-getcharter
Converted to all numbers: 1-800-4382427837
Enter Phone Number String: 1-800-leo laporte
Converted to all numbers: 1-800-536 5276783
Enter Phone Number String: 1 800 callaprogrammer
Converted to all numbers: 1 800 225527764726637
Enter Phone Number String: +1(800)Leo-Laporte
Converted to all numbers: +1(800)536-5276783
Enter Phone Number String:
C:\Users\Wulfraed\Documents\Python Progs>
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [next] | [standalone]
| From | Seymore4Head <Seymore4Head@Hotmail.invalid> |
|---|---|
| Date | 2014-10-23 10:00 -0400 |
| Message-ID | <9c2i4ahg7pqabg5bl1i5bm67ebia25p406@4ax.com> |
| In reply to | #79511 |
On Thu, 23 Oct 2014 09:23:29 -0400, Dennis Lee Bieber
<wlfraed@ix.netcom.com> wrote:
>On Thu, 23 Oct 2014 00:10:28 -0700, Larry Hudson
><orgnut@yahoo.com.dmarc.invalid> declaimed the following:
>
>
>>I know you are trying to explore lists here, but I found myself somewhat intrigued with the
>>problem itself, so I wrote a different version. This version does not use lists but only
>>strings. I'm just presenting it as-is to let you try to follow the logic, but if you ask, I'll
>>explain it in detail. It turns your long sequence of if's essentially into a single line --
>>unfortunately 's' and 'z' have to be handled as special-cases, which turns that single line into
>>a six-line if/elif/else set. You might consider this line 'tricky', but I'll just say it's just
>>looking at the problem from a different viewpoint. BTW, this version accepts upper-case as well
>>as lower-case. isdigit() and isalpha() are standard string methods.
>>
>
><SNIP>
>
> This is another example where changing data structures can simplify
>things a lot...
>
>-=-=-=-=-=-=-
>keys = { "a" : "2", "b" : "2", "c" : "2", # 1 is not assigned
> "d" : "3", "e" : "3", "f" : "3",
> "g" : "4", "h" : "4", "i" : "4",
> "j" : "5", "k" : "5", "l" : "5",
> "m" : "6", "n" : "6", "o" : "6",
> "p" : "7", "q" : "7", "r" : "7", "s" : "7",
> "t" : "8", "u" : "8", "v" : "8",
> "w" : "9", "x" : "9", "y" : "9", "z" : "9" }
>
>def textToNumber(inp):
> outp = []
> for c in inp.lower():
> outp.append(keys.get(c, c))
> return "".join(outp)
>
>if __name__ == "__main__":
> while True:
> #NOTE: Python 2.7!
> aNumStr = raw_input("\nEnter Phone Number String: ")
> if not aNumStr: break
> print "Converted to all numbers: %s" % textToNumber(aNumStr)
>
I'll have a look at this one too. I haven't used a dictionary yet.
Thanks
>-=-=-=-=-=-=-
>Microsoft Windows [Version 6.1.7601]
>Copyright (c) 2009 Microsoft Corporation. All rights reserved.
>
>C:\Users\Wulfraed\Documents\Python Progs>Phone.py
>
>Enter Phone Number String: 1-800-getcharter
>Converted to all numbers: 1-800-4382427837
>
>Enter Phone Number String: 1-800-leo laporte
>Converted to all numbers: 1-800-536 5276783
>
>Enter Phone Number String: 1 800 callaprogrammer
>Converted to all numbers: 1 800 225527764726637
>
>Enter Phone Number String: +1(800)Leo-Laporte
>Converted to all numbers: +1(800)536-5276783
>
>Enter Phone Number String:
>
>C:\Users\Wulfraed\Documents\Python Progs>
[toc] | [prev] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2014-10-23 20:23 -0400 |
| Message-ID | <mailman.15120.1414110245.18130.python-list@python.org> |
| In reply to | #79517 |
On Thu, 23 Oct 2014 10:00:38 -0400, Seymore4Head
<Seymore4Head@Hotmail.invalid> declaimed the following:
>I'll have a look at this one too. I haven't used a dictionary yet.
When all you have is a hammer, everything is a nail.
The Python Tutorial (what's that up to -- 100 pages now? {I read it
back in the days of Python 1.5}) and the Library Reference chapter on
built-in data types should be required reading of all...
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [next] | [standalone]
| From | Seymore4Head <Seymore4Head@Hotmail.invalid> |
|---|---|
| Date | 2014-10-23 09:53 -0400 |
| Message-ID | <u12i4a9u9t4ch02f1ga3ganepsso983p4d@4ax.com> |
| In reply to | #79503 |
On Thu, 23 Oct 2014 00:10:28 -0700, Larry Hudson <orgnut@yahoo.com>
wrote:
>On 10/22/2014 03:30 PM, Seymore4Head wrote:
>> On Wed, 22 Oct 2014 16:30:37 -0400, Seymore4Head
>> <Seymore4Head@Hotmail.invalid> wrote:
>>
>> One more question.
>> if y in str(range(10)
>> Why doesn't that work.
>> I commented it out and just did it "long hand"
>>
>> def nametonumber(name):
>> lst=[]
>> nx=[]
>> for x in (name):
>> lst.append(x)
>> for y in (lst):
>> #if y in str(range(10)):
>> if y in "1234567890":
>> nx.append(y)
>> if y in " -()":
>> nx.append(y)
>> if y in "abc":
>> nx.append("2")
>> if y in "def":
>> nx.append("3")
>> if y in "ghi":
>> nx.append("4")
>> if y in "jkl":
>> nx.append("5")
>> if y in "mno":
>> nx.append("6")
>> if y in "pqrs":
>> nx.append("7")
>> if y in "tuv":
>> nx.append("8")
>> if y in "wxyz":
>> nx.append("9")
>> number="".join(str(e) for e in nx)
>> return (number)
>> a="1-800-getcharter"
>> print (nametonumber(a))#1800 438 2427 837
>> a="1-800-leo laporte"
>> print (nametonumber(a))
>> a="1 800 callaprogrammer"
>> print (nametonumber(a))
>>
>I know you are trying to explore lists here, but I found myself somewhat intrigued with the
>problem itself, so I wrote a different version. This version does not use lists but only
>strings. I'm just presenting it as-is to let you try to follow the logic, but if you ask, I'll
>explain it in detail. It turns your long sequence of if's essentially into a single line --
>unfortunately 's' and 'z' have to be handled as special-cases, which turns that single line into
>a six-line if/elif/else set. You might consider this line 'tricky', but I'll just say it's just
>looking at the problem from a different viewpoint. BTW, this version accepts upper-case as well
>as lower-case. isdigit() and isalpha() are standard string methods.
>
>#------ Code ----------
>def name2number(name):
> nstr = '' # Phone-number string to return
> codes = 'abcdefghijklmnopqrtuvwxy' # Note missing s and z
>
> for ch in name:
> if ch in " -()":
> nstr += ch
> elif ch.isdigit():
> nstr += ch
> elif ch.isalpha():
> ch = ch.lower()
> # S and Z are special cases
> if ch == 's':
> nstr += '7'
> elif ch == 'z':
> nstr += '9'
> else:
> nstr += str(codes.index(ch) // 3 + 2)
> return nstr
>#------- End of Code ---------
>
>A possible variation would be to make nstr a list instead of a string, and use .append() instead
>of the +=, and finally return the string by using join() on the list. Also, the if and first
>elif in the for could be combined: if ch in " -()" or ch.isdigit():
>
> -=- Larry -=-
Sure I will have a look at it. I am always open on better ways to do
something.
Thanks
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2014-10-23 09:15 +0000 |
| Message-ID | <m2agv4$bjt$1@dont-email.me> |
| In reply to | #79475 |
On Wed, 22 Oct 2014 18:30:17 -0400, Seymore4Head wrote: > One more question. > if y in str(range(10) > Why doesn't that work. > I commented it out and just did it "long hand" In the last post I made, I suggested to you the mechanisms of using the python console and using code which prints out variables after every line. Try the following 3 commands at the console: >>> 10 >>> range(10) >>> str(range(10)) 10 is just the number 10 range(10) is a list of 10 integers in the sequence 0 to 9 str(range(10)) is? Please stop the stab in the dark trial and error coding followed by the plaintive "why doesn't it work" wailing, and put some effort into reading and understanding the manuals. If a function doesn't do what you expect with the input you think you've given it, there is invariably one of three causes: a) The input you actually gave it isn't the input you thought you gave it b) You didn't read the description of the function, and it doesn't in fact do what you thought c) Both a and b above -- Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | Seymore4Head <Seymore4Head@Hotmail.invalid> |
|---|---|
| Date | 2014-10-23 10:04 -0400 |
| Message-ID | <hn2i4alih8vemi6vfbo07okmslj5anjkc3@4ax.com> |
| In reply to | #79507 |
On Thu, 23 Oct 2014 09:15:16 +0000 (UTC), Denis McMahon <denismfmcmahon@gmail.com> wrote: >On Wed, 22 Oct 2014 18:30:17 -0400, Seymore4Head wrote: > >> One more question. >> if y in str(range(10) >> Why doesn't that work. >> I commented it out and just did it "long hand" > >In the last post I made, I suggested to you the mechanisms of using the >python console and using code which prints out variables after every line. > >Try the following 3 commands at the console: > >>>> 10 >>>> range(10) >>>> str(range(10)) > >10 is just the number 10 >range(10) is a list of 10 integers in the sequence 0 to 9 >str(range(10)) is? > >Please stop the stab in the dark trial and error coding followed by the >plaintive "why doesn't it work" wailing, and put some effort into reading >and understanding the manuals. > >If a function doesn't do what you expect with the input you think you've >given it, there is invariably one of three causes: > >a) The input you actually gave it isn't the input you thought you gave it >b) You didn't read the description of the function, and it doesn't in >fact do what you thought >c) Both a and b above Ok Thanks
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2014-10-23 15:55 +0000 |
| Message-ID | <m2b8dm$u0g$1@dont-email.me> |
| In reply to | #79520 |
On Thu, 23 Oct 2014 10:04:56 -0400, Seymore4Head wrote: > On Thu, 23 Oct 2014 09:15:16 +0000 (UTC), Denis McMahon > <denismfmcmahon@gmail.com> wrote: >>Try the following 3 commands at the console: You obviously didn't, so I'll try again. Try each of the following three commands in the python console at the ">>>" prompt. 1) 10 2) range(10) 3) str(range(10)) Show *and* describe the output in each case. Describing the output that you see is actually the key here, as it will allow us to assess whether you understand what you are actually seeing or not, and if you don't understand the output you see in the console, then we need to fix that very fundamental and basic issue before moving on to more complex stuff! > Ok Thanks You were expected to answer the question in the original. I have now set it as a clearer and more specific task. If you're not going to do these things that are intended to help you learn some of the basic features of the language, then I and everyone else here that has so far been attempting to help you are wasting our time. -- Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | Seymore4Head <Seymore4Head@Hotmail.invalid> |
|---|---|
| Date | 2014-10-23 13:01 -0400 |
| Message-ID | <m8ci4a5micmvg37chdtg13bodijb1m0935@4ax.com> |
| In reply to | #79537 |
On Thu, 23 Oct 2014 15:55:35 +0000 (UTC), Denis McMahon <denismfmcmahon@gmail.com> wrote: >On Thu, 23 Oct 2014 10:04:56 -0400, Seymore4Head wrote: > >> On Thu, 23 Oct 2014 09:15:16 +0000 (UTC), Denis McMahon >> <denismfmcmahon@gmail.com> wrote: > >>>Try the following 3 commands at the console: > >You obviously didn't, so I'll try again. Try each of the following three >commands in the python console at the ">>>" prompt. > >1) 10 10 >2) range(10) range(0, 10) >3) str(range(10)) 'range(0, 10)' [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] > >Show *and* describe the output in each case. Describing the output that >you see is actually the key here, as it will allow us to assess whether >you understand what you are actually seeing or not, and if you don't >understand the output you see in the console, then we need to fix that >very fundamental and basic issue before moving on to more complex stuff! > >> Ok Thanks > >You were expected to answer the question in the original. I have now set >it as a clearer and more specific task. > >If you're not going to do these things that are intended to help you >learn some of the basic features of the language, then I and everyone >else here that has so far been attempting to help you are wasting our >time. I did try them. I may have missed replying your to your specific comment, but I tried them. BTW str(range (10)) does work with Python 2 which is where I may have got the idea. I happened to be using Python 3 at the time I tried to implement it. It is a little confusing jumping back and forth, but for the moment, I am going to tough it out. I do appreciate all the help too.
[toc] | [prev] | [next] | [standalone]
| From | Seymore4Head <Seymore4Head@Hotmail.invalid> |
|---|---|
| Date | 2014-10-23 13:07 -0400 |
| Message-ID | <gbdi4a5jebbgfkta4999faupa8s3afu5s3@4ax.com> |
| In reply to | #79541 |
On Thu, 23 Oct 2014 13:01:18 -0400, Seymore4Head <Seymore4Head@Hotmail.invalid> wrote: >On Thu, 23 Oct 2014 15:55:35 +0000 (UTC), Denis McMahon ><denismfmcmahon@gmail.com> wrote: > >>On Thu, 23 Oct 2014 10:04:56 -0400, Seymore4Head wrote: >> >>> On Thu, 23 Oct 2014 09:15:16 +0000 (UTC), Denis McMahon >>> <denismfmcmahon@gmail.com> wrote: >> >>>>Try the following 3 commands at the console: >> >>You obviously didn't, so I'll try again. Try each of the following three >>commands in the python console at the ">>>" prompt. >> >>1) 10 >10 > >>2) range(10) >range(0, 10) > >>3) str(range(10)) >'range(0, 10)' >[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >> BTW I forgot to add that example 2 and 3 don't seem to be too useful in Python 3, but they are in Python 2. I don't understand how the Python 3 is an improved version. >>Show *and* describe the output in each case. Describing the output that >>you see is actually the key here, as it will allow us to assess whether >>you understand what you are actually seeing or not, and if you don't >>understand the output you see in the console, then we need to fix that >>very fundamental and basic issue before moving on to more complex stuff! >> >>> Ok Thanks >> >>You were expected to answer the question in the original. I have now set >>it as a clearer and more specific task. >> >>If you're not going to do these things that are intended to help you >>learn some of the basic features of the language, then I and everyone >>else here that has so far been attempting to help you are wasting our >>time. > >I did try them. I may have missed replying your to your specific >comment, but I tried them. > >BTW str(range (10)) does work with Python 2 which is where I may have >got the idea. I happened to be using Python 3 at the time I tried to >implement it. It is a little confusing jumping back and forth, but >for the moment, I am going to tough it out. > >I do appreciate all the help too.
[toc] | [prev] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2014-10-23 13:39 -0600 |
| Subject | Re: I am out of trial and error again Lists |
| Message-ID | <mailman.15117.1414093191.18130.python-list@python.org> |
| In reply to | #79543 |
On Thu, Oct 23, 2014 at 11:07 AM, Seymore4Head <Seymore4Head@hotmail.invalid> wrote: > BTW I forgot to add that example 2 and 3 don't seem to be too useful > in Python 3, but they are in Python 2. I don't understand how the > Python 3 is an improved version. In Python 2, range returns a list containing all the requested elements. This is simple to work with but often not desirable, because it forces the entire sequence to be loaded into memory at once. Large ranges may cause excessive memory use and related slowdowns, while very large ranges may not even be usable. In Python 3, range returns a compact object that knows what elements it contains and can iterate over them (which is the most common use of ranges by far), but without needing to load them all into memory at once. While iterating, only the current element needs to exist in memory. You can still get the range as a list if you want it, by calling list(range(10)), but it doesn't force you to create a list, which makes it more versatile than the Python 2 construct. The more specialized data structure used in Python 3 also allows for certain optimizations, for example membership testing. In Python 2, if you do the test "97 in range(100)", it has to construct a 100-element list and then iterate over 97 of the elements before discovering that the list does in fact contain the number 97. The Python 3 range object knows what the bounds of the range are, so all it has to do is check that 0 <= 97 < 100 to know that the number 97 is included in the range.
[toc] | [prev] | [next] | [standalone]
| From | Seymore4Head <Seymore4Head@Hotmail.invalid> |
|---|---|
| Date | 2014-10-23 16:15 -0400 |
| Subject | Re: I am out of trial and error again Lists |
| Message-ID | <hcoi4atsj2i6bb3p16lkatucr0l0429it6@4ax.com> |
| In reply to | #79546 |
On Thu, 23 Oct 2014 13:39:06 -0600, Ian Kelly <ian.g.kelly@gmail.com> wrote: >On Thu, Oct 23, 2014 at 11:07 AM, Seymore4Head ><Seymore4Head@hotmail.invalid> wrote: >> BTW I forgot to add that example 2 and 3 don't seem to be too useful >> in Python 3, but they are in Python 2. I don't understand how the >> Python 3 is an improved version. > >In Python 2, range returns a list containing all the requested >elements. This is simple to work with but often not desirable, because >it forces the entire sequence to be loaded into memory at once. Large >ranges may cause excessive memory use and related slowdowns, while >very large ranges may not even be usable. > >In Python 3, range returns a compact object that knows what elements >it contains and can iterate over them (which is the most common use of >ranges by far), but without needing to load them all into memory at >once. While iterating, only the current element needs to exist in >memory. You can still get the range as a list if you want it, by >calling list(range(10)), but it doesn't force you to create a list, >which makes it more versatile than the Python 2 construct. > >The more specialized data structure used in Python 3 also allows for >certain optimizations, for example membership testing. In Python 2, if >you do the test "97 in range(100)", it has to construct a 100-element >list and then iterate over 97 of the elements before discovering that >the list does in fact contain the number 97. The Python 3 range object >knows what the bounds of the range are, so all it has to do is check >that 0 <= 97 < 100 to know that the number 97 is included in the >range. I agree that does seem improved. Thanks
[toc] | [prev] | [next] | [standalone]
| From | Seymore4Head <Seymore4Head@Hotmail.invalid> |
|---|---|
| Date | 2014-10-23 16:44 -0400 |
| Subject | Re: I am out of trial and error again Lists |
| Message-ID | <m8pi4a9la35qts0812kmo9tcdto9mgpm0a@4ax.com> |
| In reply to | #79546 |
On Thu, 23 Oct 2014 13:39:06 -0600, Ian Kelly <ian.g.kelly@gmail.com>
wrote:
>On Thu, Oct 23, 2014 at 11:07 AM, Seymore4Head
><Seymore4Head@hotmail.invalid> wrote:
>> BTW I forgot to add that example 2 and 3 don't seem to be too useful
>> in Python 3, but they are in Python 2. I don't understand how the
>> Python 3 is an improved version.
>
>In Python 2, range returns a list containing all the requested
>elements. This is simple to work with but often not desirable, because
>it forces the entire sequence to be loaded into memory at once. Large
>ranges may cause excessive memory use and related slowdowns, while
>very large ranges may not even be usable.
>
>In Python 3, range returns a compact object that knows what elements
>it contains and can iterate over them (which is the most common use of
>ranges by far), but without needing to load them all into memory at
>once. While iterating, only the current element needs to exist in
>memory. You can still get the range as a list if you want it, by
>calling list(range(10)), but it doesn't force you to create a list,
>which makes it more versatile than the Python 2 construct.
>
>The more specialized data structure used in Python 3 also allows for
>certain optimizations, for example membership testing. In Python 2, if
>you do the test "97 in range(100)", it has to construct a 100-element
>list and then iterate over 97 of the elements before discovering that
>the list does in fact contain the number 97. The Python 3 range object
>knows what the bounds of the range are, so all it has to do is check
>that 0 <= 97 < 100 to know that the number 97 is included in the
>range.
I tried to make range(10) work in Python 3 by:
if int(y) in range(10):
name.append(str(y))
It doesn't.
def nametonumber(name):
lst=[]
for y in (name):
y.lower()
if int(y) in range(10):
name.append(str(y))
if y in " -()":
name.append(y)
if y in "abc":
name.append("2")
if y in "def":
name.append("3")
if y in "ghi":
name.append("4")
if y in "jkl":
name.append("5")
if y in "mno":
name.append("6")
if y in "pqrs":
name.append("7")
if y in "tuv":
name.append("8")
if y in "wxyz":
name.append("9")
number="".join(str(e) for e in name)
return (number)
a="1-800-getcharter"
print (nametonumber(a))#1800 438 2427 837
a="1-800-leo laporte"
print (nametonumber(a))
a="1 800 callaprogrammer"
print (nametonumber(a))
[toc] | [prev] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2014-10-23 22:03 +0100 |
| Subject | Re: I am out of trial and error again Lists |
| Message-ID | <mailman.15118.1414098214.18130.python-list@python.org> |
| In reply to | #79548 |
On 2014-10-23 21:44, Seymore4Head wrote:
[snip]
>
> I tried to make range(10) work in Python 3 by:
> if int(y) in range(10):
> name.append(str(y))
>
> It doesn't.
>
You didn't say what happened when you tried, but I can guess.
When given, say, "g", it complains that it's not valid. Well, "g" isn't
a valid digit, so no surprise there!
> def nametonumber(name):
> lst=[]
> for y in (name):
> y.lower()
The .lower method _returns_ its result, which is just discarded.
What you need is:
y = y.lower()
> if int(y) in range(10):
Non-digits don't have a numeric value, so that can fail.
> name.append(str(y))
y is already a string, so str(y) is pointless.
> if y in " -()":
> name.append(y)
> if y in "abc":
> name.append("2")
> if y in "def":
> name.append("3")
> if y in "ghi":
> name.append("4")
> if y in "jkl":
> name.append("5")
> if y in "mno":
> name.append("6")
> if y in "pqrs":
> name.append("7")
> if y in "tuv":
> name.append("8")
> if y in "wxyz":
> name.append("9")
> number="".join(str(e) for e in name)
The elements of the list name are already strings.
> return (number)
> a="1-800-getcharter"
> print (nametonumber(a))#1800 438 2427 837
> a="1-800-leo laporte"
> print (nametonumber(a))
> a="1 800 callaprogrammer"
> print (nametonumber(a))
>
[toc] | [prev] | [next] | [standalone]
| From | Larry Hudson <orgnut@yahoo.com> |
|---|---|
| Date | 2014-10-23 19:13 -0700 |
| Subject | Re: I am out of trial and error again Lists |
| Message-ID | <NoadnYiT9cp8KNTJnZ2dnUU7-KmdnZ2d@giganews.com> |
| In reply to | #79548 |
On 10/23/2014 01:44 PM, Seymore4Head wrote:
<snip>
> I tried to make range(10) work in Python 3 by:
> if int(y) in range(10):
> name.append(str(y))
>
> It doesn't.
>
That's true, it doesn't. However, did you actually READ the error message it gives? It has
NOTHING to do with range().
BTW, did you notice that I cut out most of the quote of your post? I do that because the parts
I cut out are not relevant to what I'm referring to. PLEASE, try that in your posts -- that
will make them much less annoying to the other people here. Quote enough to maintain context,
but more is rarely necessary.
Also as others here have already pointed out, if you are replying to different parts of a post,
use an interleaved style:
<Some quoted text>
[Your reply]
<More quoted text>
[Another reply]
<Even more...
[etc.
That style is greatly appreciated by the regular participants here.
-=- Larry -=-
[toc] | [prev] | [next] | [standalone]
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2014-10-23 23:14 -0400 |
| Subject | Re: I am out of trial and error again Lists |
| Message-ID | <mailman.15121.1414120492.18130.python-list@python.org> |
| In reply to | #79543 |
On 10/23/2014 3:39 PM, Ian Kelly wrote: > On Thu, Oct 23, 2014 at 11:07 AM, Seymore4Head > <Seymore4Head@hotmail.invalid> wrote: >> BTW I forgot to add that example 2 and 3 don't seem to be too useful >> in Python 3, but they are in Python 2. I don't understand how the >> Python 3 is an improved version. > > In Python 2, range returns a list containing all the requested > elements. This is simple to work with but often not desirable, because > it forces the entire sequence to be loaded into memory at once. Large > ranges may cause excessive memory use and related slowdowns, while > very large ranges may not even be usable. > > In Python 3, range returns a compact object that knows what elements > it contains and can iterate over them (which is the most common use of > ranges by far), but without needing to load them all into memory at > once. While iterating, only the current element needs to exist in > memory. You can still get the range as a list if you want it, by > calling list(range(10)), but it doesn't force you to create a list, > which makes it more versatile than the Python 2 construct. > > The more specialized data structure used in Python 3 also allows for > certain optimizations, for example membership testing. In Python 2, if > you do the test "97 in range(100)", it has to construct a 100-element > list and then iterate over 97 of the elements before discovering that > the list does in fact contain the number 97. The Python 3 range object > knows what the bounds of the range are, so all it has to do is check > that 0 <= 97 < 100 to know that the number 97 is included in the > range. Example that works 'instantly' in 3.x, but would be slightly insane in 2.x, even if you have enough memory for it to work on a 64 bit build. >>> r =range(0, 1000000000000000, 999937) >>> 3428761974385 in r False >>> 3428761974386 in r True -- Terry Jan Reedy
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-10-24 14:32 +1100 |
| Subject | Re: I am out of trial and error again Lists |
| Message-ID | <mailman.15122.1414121549.18130.python-list@python.org> |
| In reply to | #79543 |
On Fri, Oct 24, 2014 at 2:14 PM, Terry Reedy <tjreedy@udel.edu> wrote: > Example that works 'instantly' in 3.x, but would be slightly insane in 2.x, > even if you have enough memory for it to work on a 64 bit build. > >>>> r =range(0, 1000000000000000, 999937) >>>> 3428761974385 in r > False >>>> 3428761974386 in r > True That's over a billion entries. The array of pointers alone would be roughly 4GB on a 32-bit build, so there's no way that'll ever fit... on a 64-bit build, that'll take up 8GBish for the list, plus probably 24 bytes minimum per integer, so even if there's absolutely no heap overhead, you're still looking at 32GB to store that list. Yeeeouch. I think we can drop the "slightly" from your description! For comparison, a 64-bit Python 3 says: >>> sys.getsizeof(range(0, 1000000000000000, 999937)) 48 Thanks, much nicer. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Rustom Mody <rustompmody@gmail.com> |
|---|---|
| Date | 2014-10-23 21:56 -0700 |
| Message-ID | <2412654f-ac5e-4678-8956-afc4e27affb3@googlegroups.com> |
| In reply to | #79541 |
On Thursday, October 23, 2014 10:33:57 PM UTC+5:30, Seymore4Head wrote: > On Thu, 23 Oct 2014 15:55:35 +0000 (UTC), Denis McMahon wrote: > > >On Thu, 23 Oct 2014 10:04:56 -0400, Seymore4Head wrote: > > > >> On Thu, 23 Oct 2014 09:15:16 +0000 (UTC), Denis McMahon wrote: > > > >>>Try the following 3 commands at the console: > > > >You obviously didn't, so I'll try again. Try each of the following three > >commands in the python console at the ">>>" prompt. > > > >1) 10 > 10 > > >2) range(10) > range(0, 10) > > >3) str(range(10)) > 'range(0, 10)' > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] > > > >Show *and* describe the output in each case. Describing the output that > >you see is actually the key here, as it will allow us to assess whether > >you understand what you are actually seeing or not, and if you don't > >understand the output you see in the console, then we need to fix that > >very fundamental and basic issue before moving on to more complex stuff! > > > >> Ok Thanks > > > >You were expected to answer the question in the original. I have now set > >it as a clearer and more specific task. > > > >If you're not going to do these things that are intended to help you > >learn some of the basic features of the language, then I and everyone > >else here that has so far been attempting to help you are wasting our > >time. > > I did try them. I may have missed replying your to your specific > comment, but I tried them. > > BTW str(range (10)) does work with Python 2 which is where I may have > got the idea. I happened to be using Python 3 at the time I tried to > implement it. It is a little confusing jumping back and forth, but > for the moment, I am going to tough it out. > > I do appreciate all the help too. Hi Seymore! Happy to see that you are moving on from "reading much; understanding nothing; thrashing" to "reading a bit; understanding a bit" [And thanks to Denis to getting you out of your confusion-hole] So heres a small additional question set that I promise will more than repay you your time. Better done in python 2. But if you use python3, below replace range(10) with list(range(10)) So now in the python console, please try a. >>> range(10) and b. >>> print (range(10)) And then post back (without consulting google!!)¹ 1. Are they same or different? 2. If same, how come different expressions are same? 3. If different whats the difference? 4. [Most important]: When would you prefer which? ================= ¹ Actually its ok to consult google AFTER you try
[toc] | [prev] | [next] | [standalone]
| From | Seymore4Head <Seymore4Head@Hotmail.invalid> |
|---|---|
| Date | 2014-10-24 10:38 -0400 |
| Message-ID | <ogok4alrphd1n17juvq9laa326b8gm3ps9@4ax.com> |
| In reply to | #79557 |
On Thu, 23 Oct 2014 21:56:31 -0700 (PDT), Rustom Mody <rustompmody@gmail.com> wrote: >On Thursday, October 23, 2014 10:33:57 PM UTC+5:30, Seymore4Head wrote: >> On Thu, 23 Oct 2014 15:55:35 +0000 (UTC), Denis McMahon wrote: >> >> >On Thu, 23 Oct 2014 10:04:56 -0400, Seymore4Head wrote: >> > >> >> On Thu, 23 Oct 2014 09:15:16 +0000 (UTC), Denis McMahon wrote: >> > >> >>>Try the following 3 commands at the console: >> > >> >You obviously didn't, so I'll try again. Try each of the following three >> >commands in the python console at the ">>>" prompt. >> > >> >1) 10 >> 10 >> >> >2) range(10) >> range(0, 10) >> >> >3) str(range(10)) >> 'range(0, 10)' >> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >> > >> >Show *and* describe the output in each case. Describing the output that >> >you see is actually the key here, as it will allow us to assess whether >> >you understand what you are actually seeing or not, and if you don't >> >understand the output you see in the console, then we need to fix that >> >very fundamental and basic issue before moving on to more complex stuff! >> > >> >> Ok Thanks >> > >> >You were expected to answer the question in the original. I have now set >> >it as a clearer and more specific task. >> > >> >If you're not going to do these things that are intended to help you >> >learn some of the basic features of the language, then I and everyone >> >else here that has so far been attempting to help you are wasting our >> >time. >> >> I did try them. I may have missed replying your to your specific >> comment, but I tried them. >> >> BTW str(range (10)) does work with Python 2 which is where I may have >> got the idea. I happened to be using Python 3 at the time I tried to >> implement it. It is a little confusing jumping back and forth, but >> for the moment, I am going to tough it out. >> >> I do appreciate all the help too. > >Hi Seymore! > >Happy to see that you are moving on from >"reading much; understanding nothing; thrashing" > >to > >"reading a bit; understanding a bit" >[And thanks to Denis to getting you out of your confusion-hole] > >So heres a small additional question set that I promise will more than repay >you your time. > >Better done in python 2. But if you use python3, below replace >range(10) >with >list(range(10)) > >So now in the python console, please try > >a. >>>> range(10) > >and > >b. >>>> print (range(10)) > >And then post back (without consulting google!!)¹ > >1. Are they same or different? > >2. If same, how come different expressions are same? > >3. If different whats the difference? > >4. [Most important]: When would you prefer which? > >================= >¹ Actually its ok to consult google AFTER you try I do get the difference. I don't actually use Python 2. I use CodeSkulptor. I do have Python 3 installed. Actually I have Python 2 installed but IDLE defaults to Python 3. So it is a pain to actually load Python 2. Range(10) stores the min max values and loads each number in between when needed. Ian explained that very clearly. I tried list(range(10) I thought that would work in Python 3. It didn't. I spent quite a bit of time last night trying to come up with the right combination of str and int commands to make range(10) work with my simple example. It didn't. I am pretty frustrated. I am just skipping that little bit of code for the moment. Thanks everyone for your suggestions.
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-10-25 01:51 +1100 |
| Subject | Re: I am out of trial and error again Lists |
| Message-ID | <mailman.15129.1414162310.18130.python-list@python.org> |
| In reply to | #79569 |
On Sat, Oct 25, 2014 at 1:38 AM, Seymore4Head <Seymore4Head@hotmail.invalid> wrote: > I tried list(range(10) I thought that would work in Python 3. It > didn't. This is your problem: You say "it didn't work". That is almost *never* the right thing to say or to think. What happened when you tried that? Did you get a SyntaxError because of the omitted close parenthesis? Did the interpreter prompt for more input? Did a velociraptor come out of nowhere and try to kill you [1]? When you come back to python-list, you should say exactly what you did and exactly what happened, not "I tried X and it didn't work". Copy and paste from your interactive session - do NOT retype, because you introduce new errors. It's very hard to help you when you don't explain what you're doing, and just keep on telling us how frustrated you are. ChrisA [1] http://xkcd.com/292/
[toc] | [prev] | [next] | [standalone]
Page 2 of 8 — ← Prev page 1 [2] 3 4 5 6 7 8 Next page →
Back to top | Article view | comp.lang.python
csiph-web