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 4 of 8 — ← Prev page 1 2 3 [4] 5 6 7 8 Next page →
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2014-10-25 08:17 -0600 |
| Subject | Re: I am out of trial and error again Lists |
| Message-ID | <mailman.15167.1414246675.18130.python-list@python.org> |
| In reply to | #79661 |
On Sat, Oct 25, 2014 at 12:46 AM, Larry Hudson <orgnut@yahoo.com.dmarc.invalid> wrote: >> name="123-xyz-abc" >> for x in name: >> if x in range(10): > > x is a character (a one-element string). range(10) is a list of ints. A > string will never match an int. BTW, as it is used here, range(10) is for > Py2, for Py3 it needs to be list(range(10)). The last comment is incorrect. You can do membership tests on a Python 3 range object: >>> range(2, 4) range(2, 4) >>> for i in range(5): ... print(i, i in range(2, 4)) ... 0 False 1 False 2 True 3 True 4 False You can also index them: >>> range(50, 100)[37] 87 slice them: >>> range(0, 100, 2)[:25] range(0, 50, 2) get their length: >>> len(range(25, 75)) 50 search them: >>> range(25, 75).index(45) 20 and generally do most operations that you would expect to be able to do with an immutable sequence type, with the exceptions of concatenation and multiplication. And as I observed elsewhere in the thread, such operations are often more efficient on range objects than by constructing and operating on the equivalent lists.
[toc] | [prev] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2014-10-25 14:47 -0400 |
| Subject | Re: I am out of trial and error again Lists |
| Message-ID | <mailman.15171.1414262886.18130.python-list@python.org> |
| In reply to | #79606 |
On Fri, 24 Oct 2014 15:07:06 -0400, Seymore4Head
<Seymore4Head@Hotmail.invalid> declaimed the following:
>It doesn't print what I expect.
Which probably means it is working, and your expectations are wrong.
>Does it print what you expect?
>
Without running it in an interpreter...
>name="123-xyz-abc"
>for x in name:
"x" will be one character from the string
> if x in range(10):
Is that CHARACTER (1 element string) found in a range of integer
values?
> print ("Range",(x))
> if x in str(range(10)):
Is that CHARACTER found in a STRING of (Py3) 'range(0, 10)' or
(Py2) '[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]'
Now, in Py2, that should actually work -- but only by coincidence. In
Py3, only "0" and "1" will be found.
Replace all your usage of "range(10)" with a simple string "0123456789"
and see what happens...
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [next] | [standalone]
| From | sohcahtoa82@gmail.com |
|---|---|
| Date | 2014-10-24 11:57 -0700 |
| Subject | Re: I am out of trial and error again Lists |
| Message-ID | <6e065210-797a-4494-9fd5-a72f5c069869@googlegroups.com> |
| In reply to | #79598 |
On Friday, October 24, 2014 11:17:53 AM UTC-7, Seymore4Head wrote:
> On Fri, 24 Oct 2014 11:52:15 -0600, Ian Kelly <ian.g.kelly@gmail.com>
> wrote:
>
> >On Fri, Oct 24, 2014 at 11:03 AM, Seymore4Head
> ><Seymore4Head@hotmail.invalid> wrote:
> >> Actually I was a little frustrated when I added that line back in as
> >> the other lines all work.
> >> Using list(range(10)) Doesn't throw an error but it doesn't work.
> >>
> >> http://i.imgur.com/DTc5zoL.jpg
> >>
> >> The interpreter. I don't know how to use that either.
> >
> >Try both of these in the interpreter, and observe the difference:
> >
> >7 in range(10)
> >
> >"7" in range(10)
> >
> >Do you understand what the difference between 7 and "7" is?
>
> I do understand that. 7 is a number and "7" is a string.
> What my question was...and still is...is why
> Python 3 fails when I try using
> y=1 800 get charter
>
> y in range str(range(10))
> should work because y is a string and str(range(10)) should be
> "y" in str(1) fails.
> It doesn't give an error it's just not True when y is a number.
>
> These hints are just not working. I am too thick for hints. :)
> If you could use it in the code, I might understand.
> The other work arounds that were posted work.
> I have used them. str(range(10)) doesn't work.
>
> import string
> def nametonumber(name):
> lst=[]
> nx=[]
> digit=[]
> digit="".join(str(i) for i in range(10))
> for x in name:
> lst.append(x)
> for y in (lst):
> if y in list(range(1,10)):
> #if y in "1234567890":
> #if y.isdigit():
> #if y in digit:
> #if y in string.digits:
> 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(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 dialaho"
> print (nametonumber(a))
>
> Please
Your code here is actually pretty close to a correct answer. Just a few things to consider...
- Why are you converting your name string to a list? It is unnecessary. When you do "for y in <some string>", then y will still be single characters on each iteration of the loop.
- "if y in string.digits" should work fine.
- "if y in list(range(1,10)" won't work for two reasons: First, it creates a list of numbers, not strings. Second, even if it did, it would be missing the "0" digit.
- At the end, when you convert your list to a string, you don't need to use list comprehension, since nx is already a list. number = "".join(nx) should work fine.
Also, in general, you need to stop and slow down and think like a programmer. If you get an error, your instinct shouldn't be to just hack at it to make the error go away. Look at the error and try to make sense of it. Learn what the error means and try to fix the core problem.
And for @#$%'s sake...stop saying "It isn't working" and not elaborating. You've been told by every other post in this thread to show us what you did and what the error was. You've also been told to *NOT* retype what you see and to copy/paste your code and the error because when you make a typo when copying, we might see a problem that doesn't exist and then you just get more confused.
[toc] | [prev] | [next] | [standalone]
| From | Seymore4Head <Seymore4Head@Hotmail.invalid> |
|---|---|
| Date | 2014-10-24 15:09 -0400 |
| Subject | Re: I am out of trial and error again Lists |
| Message-ID | <as8l4a1kq7chq4c9vmk8rebi66hj9k00mp@4ax.com> |
| In reply to | #79605 |
On Fri, 24 Oct 2014 11:57:12 -0700 (PDT), sohcahtoa82@gmail.com wrote:
>On Friday, October 24, 2014 11:17:53 AM UTC-7, Seymore4Head wrote:
>> On Fri, 24 Oct 2014 11:52:15 -0600, Ian Kelly <ian.g.kelly@gmail.com>
>> wrote:
>>
>> >On Fri, Oct 24, 2014 at 11:03 AM, Seymore4Head
>> ><Seymore4Head@hotmail.invalid> wrote:
>> >> Actually I was a little frustrated when I added that line back in as
>> >> the other lines all work.
>> >> Using list(range(10)) Doesn't throw an error but it doesn't work.
>> >>
>> >> http://i.imgur.com/DTc5zoL.jpg
>> >>
>> >> The interpreter. I don't know how to use that either.
>> >
>> >Try both of these in the interpreter, and observe the difference:
>> >
>> >7 in range(10)
>> >
>> >"7" in range(10)
>> >
>> >Do you understand what the difference between 7 and "7" is?
>>
>> I do understand that. 7 is a number and "7" is a string.
>> What my question was...and still is...is why
>> Python 3 fails when I try using
>> y=1 800 get charter
>>
>> y in range str(range(10))
>> should work because y is a string and str(range(10)) should be
>> "y" in str(1) fails.
>> It doesn't give an error it's just not True when y is a number.
>>
>> These hints are just not working. I am too thick for hints. :)
>> If you could use it in the code, I might understand.
>> The other work arounds that were posted work.
>> I have used them. str(range(10)) doesn't work.
>>
>> import string
>> def nametonumber(name):
>> lst=[]
>> nx=[]
>> digit=[]
>> digit="".join(str(i) for i in range(10))
>> for x in name:
>> lst.append(x)
>> for y in (lst):
>> if y in list(range(1,10)):
>> #if y in "1234567890":
>> #if y.isdigit():
>> #if y in digit:
>> #if y in string.digits:
>> 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(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 dialaho"
>> print (nametonumber(a))
>>
>> Please
>
>Your code here is actually pretty close to a correct answer. Just a few things to consider...
>
>- Why are you converting your name string to a list? It is unnecessary. When you do "for y in <some string>", then y will still be single characters on each iteration of the loop.
>
>- "if y in string.digits" should work fine.
>
>- "if y in list(range(1,10)" won't work for two reasons: First, it creates a list of numbers, not strings. Second, even if it did, it would be missing the "0" digit.
>
>- At the end, when you convert your list to a string, you don't need to use list comprehension, since nx is already a list. number = "".join(nx) should work fine.
>
>Also, in general, you need to stop and slow down and think like a programmer. If you get an error, your instinct shouldn't be to just hack at it to make the error go away. Look at the error and try to make sense of it. Learn what the error means and try to fix the core problem.
>
>And for @#$%'s sake...stop saying "It isn't working" and not elaborating. You've been told by every other post in this thread to show us what you did and what the error was. You've also been told to *NOT* retype what you see and to copy/paste your code and the error because when you make a typo when copying, we might see a problem that doesn't exist and then you just get more confused.
Ok I think I may have the question you guys are looking for.
I just posted it.
See above.
But it's still broke. :(
[toc] | [prev] | [next] | [standalone]
| From | sohcahtoa82@gmail.com |
|---|---|
| Date | 2014-10-24 12:25 -0700 |
| Subject | Re: I am out of trial and error again Lists |
| Message-ID | <234a2b69-b120-48ba-b697-6ee937d7498f@googlegroups.com> |
| In reply to | #79607 |
On Friday, October 24, 2014 12:12:10 PM UTC-7, Seymore4Head wrote:
> On Fri, 24 Oct 2014 11:57:12 -0700 (PDT), sohcahtoa82@gmail.com wrote:
>
> >On Friday, October 24, 2014 11:17:53 AM UTC-7, Seymore4Head wrote:
> >> On Fri, 24 Oct 2014 11:52:15 -0600, Ian Kelly <ian.g.kelly@gmail.com>
> >> wrote:
> >>
> >> >On Fri, Oct 24, 2014 at 11:03 AM, Seymore4Head
> >> ><Seymore4Head@hotmail.invalid> wrote:
> >> >> Actually I was a little frustrated when I added that line back in as
> >> >> the other lines all work.
> >> >> Using list(range(10)) Doesn't throw an error but it doesn't work.
> >> >>
> >> >> http://i.imgur.com/DTc5zoL.jpg
> >> >>
> >> >> The interpreter. I don't know how to use that either.
> >> >
> >> >Try both of these in the interpreter, and observe the difference:
> >> >
> >> >7 in range(10)
> >> >
> >> >"7" in range(10)
> >> >
> >> >Do you understand what the difference between 7 and "7" is?
> >>
> >> I do understand that. 7 is a number and "7" is a string.
> >> What my question was...and still is...is why
> >> Python 3 fails when I try using
> >> y=1 800 get charter
> >>
> >> y in range str(range(10))
> >> should work because y is a string and str(range(10)) should be
> >> "y" in str(1) fails.
> >> It doesn't give an error it's just not True when y is a number.
> >>
> >> These hints are just not working. I am too thick for hints. :)
> >> If you could use it in the code, I might understand.
> >> The other work arounds that were posted work.
> >> I have used them. str(range(10)) doesn't work.
> >>
> >> import string
> >> def nametonumber(name):
> >> lst=[]
> >> nx=[]
> >> digit=[]
> >> digit="".join(str(i) for i in range(10))
> >> for x in name:
> >> lst.append(x)
> >> for y in (lst):
> >> if y in list(range(1,10)):
> >> #if y in "1234567890":
> >> #if y.isdigit():
> >> #if y in digit:
> >> #if y in string.digits:
> >> 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(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 dialaho"
> >> print (nametonumber(a))
> >>
> >> Please
> >
> >Your code here is actually pretty close to a correct answer. Just a few things to consider...
> >
> >- Why are you converting your name string to a list? It is unnecessary. When you do "for y in <some string>", then y will still be single characters on each iteration of the loop.
> >
> >- "if y in string.digits" should work fine.
> >
> >- "if y in list(range(1,10)" won't work for two reasons: First, it creates a list of numbers, not strings. Second, even if it did, it would be missing the "0" digit.
> >
> >- At the end, when you convert your list to a string, you don't need to use list comprehension, since nx is already a list. number = "".join(nx) should work fine.
> >
> >Also, in general, you need to stop and slow down and think like a programmer. If you get an error, your instinct shouldn't be to just hack at it to make the error go away. Look at the error and try to make sense of it. Learn what the error means and try to fix the core problem.
> >
> >And for @#$%'s sake...stop saying "It isn't working" and not elaborating. You've been told by every other post in this thread to show us what you did and what the error was. You've also been told to *NOT* retype what you see and to copy/paste your code and the error because when you make a typo when copying, we might see a problem that doesn't exist and then you just get more confused.
>
> Ok I think I may have the question you guys are looking for.
> I just posted it.
> See above.
>
> But it's still broke. :(
str(range(10)) doesn't do what you think it does.
Run 'print(str(range(10)))' and look at what you get.
[toc] | [prev] | [next] | [standalone]
| From | Seymore4Head <Seymore4Head@Hotmail.invalid> |
|---|---|
| Date | 2014-10-24 15:33 -0400 |
| Subject | Re: I am out of trial and error again Lists |
| Message-ID | <38al4a9aefpve7vk3e0080rljql72pel5p@4ax.com> |
| In reply to | #79608 |
On Fri, 24 Oct 2014 12:25:33 -0700 (PDT), sohcahtoa82@gmail.com wrote:
>On Friday, October 24, 2014 12:12:10 PM UTC-7, Seymore4Head wrote:
>> On Fri, 24 Oct 2014 11:57:12 -0700 (PDT), sohcahtoa82@gmail.com wrote:
>>
>> >On Friday, October 24, 2014 11:17:53 AM UTC-7, Seymore4Head wrote:
>> >> On Fri, 24 Oct 2014 11:52:15 -0600, Ian Kelly <ian.g.kelly@gmail.com>
>> >> wrote:
>> >>
>> >> >On Fri, Oct 24, 2014 at 11:03 AM, Seymore4Head
>> >> ><Seymore4Head@hotmail.invalid> wrote:
>> >> >> Actually I was a little frustrated when I added that line back in as
>> >> >> the other lines all work.
>> >> >> Using list(range(10)) Doesn't throw an error but it doesn't work.
>> >> >>
>> >> >> http://i.imgur.com/DTc5zoL.jpg
>> >> >>
>> >> >> The interpreter. I don't know how to use that either.
>> >> >
>> >> >Try both of these in the interpreter, and observe the difference:
>> >> >
>> >> >7 in range(10)
>> >> >
>> >> >"7" in range(10)
>> >> >
>> >> >Do you understand what the difference between 7 and "7" is?
>> >>
>> >> I do understand that. 7 is a number and "7" is a string.
>> >> What my question was...and still is...is why
>> >> Python 3 fails when I try using
>> >> y=1 800 get charter
>> >>
>> >> y in range str(range(10))
>> >> should work because y is a string and str(range(10)) should be
>> >> "y" in str(1) fails.
>> >> It doesn't give an error it's just not True when y is a number.
>> >>
>> >> These hints are just not working. I am too thick for hints. :)
>> >> If you could use it in the code, I might understand.
>> >> The other work arounds that were posted work.
>> >> I have used them. str(range(10)) doesn't work.
>> >>
>> >> import string
>> >> def nametonumber(name):
>> >> lst=[]
>> >> nx=[]
>> >> digit=[]
>> >> digit="".join(str(i) for i in range(10))
>> >> for x in name:
>> >> lst.append(x)
>> >> for y in (lst):
>> >> if y in list(range(1,10)):
>> >> #if y in "1234567890":
>> >> #if y.isdigit():
>> >> #if y in digit:
>> >> #if y in string.digits:
>> >> 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(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 dialaho"
>> >> print (nametonumber(a))
>> >>
>> >> Please
>> >
>> >Your code here is actually pretty close to a correct answer. Just a few things to consider...
>> >
>> >- Why are you converting your name string to a list? It is unnecessary. When you do "for y in <some string>", then y will still be single characters on each iteration of the loop.
>> >
>> >- "if y in string.digits" should work fine.
>> >
>> >- "if y in list(range(1,10)" won't work for two reasons: First, it creates a list of numbers, not strings. Second, even if it did, it would be missing the "0" digit.
>> >
>> >- At the end, when you convert your list to a string, you don't need to use list comprehension, since nx is already a list. number = "".join(nx) should work fine.
>> >
>> >Also, in general, you need to stop and slow down and think like a programmer. If you get an error, your instinct shouldn't be to just hack at it to make the error go away. Look at the error and try to make sense of it. Learn what the error means and try to fix the core problem.
>> >
>> >And for @#$%'s sake...stop saying "It isn't working" and not elaborating. You've been told by every other post in this thread to show us what you did and what the error was. You've also been told to *NOT* retype what you see and to copy/paste your code and the error because when you make a typo when copying, we might see a problem that doesn't exist and then you just get more confused.
>>
>> Ok I think I may have the question you guys are looking for.
>> I just posted it.
>> See above.
>>
>> But it's still broke. :(
>
>str(range(10)) doesn't do what you think it does.
>
>Run 'print(str(range(10)))' and look at what you get.
Yeah, I know that. My question is why?
The answer was that Python 3 only stores the min and max values but
you can still iterate over them.
I don't think that means what I think it means.
[toc] | [prev] | [next] | [standalone]
| From | sohcahtoa82@gmail.com |
|---|---|
| Date | 2014-10-24 12:55 -0700 |
| Subject | Re: I am out of trial and error again Lists |
| Message-ID | <42fdc118-a0f7-453e-baf6-9f93f6eb9321@googlegroups.com> |
| In reply to | #79609 |
On Friday, October 24, 2014 12:36:23 PM UTC-7, Seymore4Head wrote:
> On Fri, 24 Oct 2014 12:25:33 -0700 (PDT), sohcahtoa82@gmail.com wrote:
>
> >On Friday, October 24, 2014 12:12:10 PM UTC-7, Seymore4Head wrote:
> >> On Fri, 24 Oct 2014 11:57:12 -0700 (PDT), sohcahtoa82@gmail.com wrote:
> >>
> >> >On Friday, October 24, 2014 11:17:53 AM UTC-7, Seymore4Head wrote:
> >> >> On Fri, 24 Oct 2014 11:52:15 -0600, Ian Kelly <ian.g.kelly@gmail.com>
> >> >> wrote:
> >> >>
> >> >> >On Fri, Oct 24, 2014 at 11:03 AM, Seymore4Head
> >> >> ><Seymore4Head@hotmail.invalid> wrote:
> >> >> >> Actually I was a little frustrated when I added that line back in as
> >> >> >> the other lines all work.
> >> >> >> Using list(range(10)) Doesn't throw an error but it doesn't work.
> >> >> >>
> >> >> >> http://i.imgur.com/DTc5zoL.jpg
> >> >> >>
> >> >> >> The interpreter. I don't know how to use that either.
> >> >> >
> >> >> >Try both of these in the interpreter, and observe the difference:
> >> >> >
> >> >> >7 in range(10)
> >> >> >
> >> >> >"7" in range(10)
> >> >> >
> >> >> >Do you understand what the difference between 7 and "7" is?
> >> >>
> >> >> I do understand that. 7 is a number and "7" is a string.
> >> >> What my question was...and still is...is why
> >> >> Python 3 fails when I try using
> >> >> y=1 800 get charter
> >> >>
> >> >> y in range str(range(10))
> >> >> should work because y is a string and str(range(10)) should be
> >> >> "y" in str(1) fails.
> >> >> It doesn't give an error it's just not True when y is a number.
> >> >>
> >> >> These hints are just not working. I am too thick for hints. :)
> >> >> If you could use it in the code, I might understand.
> >> >> The other work arounds that were posted work.
> >> >> I have used them. str(range(10)) doesn't work.
> >> >>
> >> >> import string
> >> >> def nametonumber(name):
> >> >> lst=[]
> >> >> nx=[]
> >> >> digit=[]
> >> >> digit="".join(str(i) for i in range(10))
> >> >> for x in name:
> >> >> lst.append(x)
> >> >> for y in (lst):
> >> >> if y in list(range(1,10)):
> >> >> #if y in "1234567890":
> >> >> #if y.isdigit():
> >> >> #if y in digit:
> >> >> #if y in string.digits:
> >> >> 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(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 dialaho"
> >> >> print (nametonumber(a))
> >> >>
> >> >> Please
> >> >
> >> >Your code here is actually pretty close to a correct answer. Just a few things to consider...
> >> >
> >> >- Why are you converting your name string to a list? It is unnecessary. When you do "for y in <some string>", then y will still be single characters on each iteration of the loop.
> >> >
> >> >- "if y in string.digits" should work fine.
> >> >
> >> >- "if y in list(range(1,10)" won't work for two reasons: First, it creates a list of numbers, not strings. Second, even if it did, it would be missing the "0" digit.
> >> >
> >> >- At the end, when you convert your list to a string, you don't need to use list comprehension, since nx is already a list. number = "".join(nx) should work fine.
> >> >
> >> >Also, in general, you need to stop and slow down and think like a programmer. If you get an error, your instinct shouldn't be to just hack at it to make the error go away. Look at the error and try to make sense of it. Learn what the error means and try to fix the core problem.
> >> >
> >> >And for @#$%'s sake...stop saying "It isn't working" and not elaborating. You've been told by every other post in this thread to show us what you did and what the error was. You've also been told to *NOT* retype what you see and to copy/paste your code and the error because when you make a typo when copying, we might see a problem that doesn't exist and then you just get more confused.
> >>
> >> Ok I think I may have the question you guys are looking for.
> >> I just posted it.
> >> See above.
> >>
> >> But it's still broke. :(
> >
> >str(range(10)) doesn't do what you think it does.
> >
> >Run 'print(str(range(10)))' and look at what you get.
>
> Yeah, I know that. My question is why?
> The answer was that Python 3 only stores the min and max values but
> you can still iterate over them.
> I don't think that means what I think it means.
"You can iterate over them" pretty much just means you can use them as the source of a 'for' loop. But in your case, when you're calling 'for y in str(range(10))', you're not using 'range(10)' as the source of your loop, you're using the result of a str() function call, and you're calling str() on range(), which doesn't return a concrete value in Python 3. If you try to print a range(), you're just getting a string containing your original call to range.
And that's why you're seeing the 1 and a in your output. str(range(10)) returns the string 'range(10)'.
Like I said in a previous post, use 'string.digits'. Try this test code and see what you get:
import string
name="123-xyz-abc"
print("string.digits is", string.digits)
for x in name:
if x in range(10):
print ("Range",(x))
if x in string.digits:
print ("string.digits",(x))
[toc] | [prev] | [next] | [standalone]
| From | Seymore4Head <Seymore4Head@Hotmail.invalid> |
|---|---|
| Date | 2014-10-24 16:00 -0400 |
| Subject | Re: I am out of trial and error again Lists |
| Message-ID | <msbl4ah1a92pj0sf5se30quikahpae1kdk@4ax.com> |
| In reply to | #79610 |
On Fri, 24 Oct 2014 12:55:19 -0700 (PDT), sohcahtoa82@gmail.com wrote:
>On Friday, October 24, 2014 12:36:23 PM UTC-7, Seymore4Head wrote:
>> On Fri, 24 Oct 2014 12:25:33 -0700 (PDT), sohcahtoa82@gmail.com wrote:
>>
>> >On Friday, October 24, 2014 12:12:10 PM UTC-7, Seymore4Head wrote:
>> >> On Fri, 24 Oct 2014 11:57:12 -0700 (PDT), sohcahtoa82@gmail.com wrote:
>> >>
>> >> >On Friday, October 24, 2014 11:17:53 AM UTC-7, Seymore4Head wrote:
>> >> >> On Fri, 24 Oct 2014 11:52:15 -0600, Ian Kelly <ian.g.kelly@gmail.com>
>> >> >> wrote:
>> >> >>
>> >> >> >On Fri, Oct 24, 2014 at 11:03 AM, Seymore4Head
>> >> >> ><Seymore4Head@hotmail.invalid> wrote:
>> >> >> >> Actually I was a little frustrated when I added that line back in as
>> >> >> >> the other lines all work.
>> >> >> >> Using list(range(10)) Doesn't throw an error but it doesn't work.
>> >> >> >>
>> >> >> >> http://i.imgur.com/DTc5zoL.jpg
>> >> >> >>
>> >> >> >> The interpreter. I don't know how to use that either.
>> >> >> >
>> >> >> >Try both of these in the interpreter, and observe the difference:
>> >> >> >
>> >> >> >7 in range(10)
>> >> >> >
>> >> >> >"7" in range(10)
>> >> >> >
>> >> >> >Do you understand what the difference between 7 and "7" is?
>> >> >>
>> >> >> I do understand that. 7 is a number and "7" is a string.
>> >> >> What my question was...and still is...is why
>> >> >> Python 3 fails when I try using
>> >> >> y=1 800 get charter
>> >> >>
>> >> >> y in range str(range(10))
>> >> >> should work because y is a string and str(range(10)) should be
>> >> >> "y" in str(1) fails.
>> >> >> It doesn't give an error it's just not True when y is a number.
>> >> >>
>> >> >> These hints are just not working. I am too thick for hints. :)
>> >> >> If you could use it in the code, I might understand.
>> >> >> The other work arounds that were posted work.
>> >> >> I have used them. str(range(10)) doesn't work.
>> >> >>
>> >> >> import string
>> >> >> def nametonumber(name):
>> >> >> lst=[]
>> >> >> nx=[]
>> >> >> digit=[]
>> >> >> digit="".join(str(i) for i in range(10))
>> >> >> for x in name:
>> >> >> lst.append(x)
>> >> >> for y in (lst):
>> >> >> if y in list(range(1,10)):
>> >> >> #if y in "1234567890":
>> >> >> #if y.isdigit():
>> >> >> #if y in digit:
>> >> >> #if y in string.digits:
>> >> >> 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(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 dialaho"
>> >> >> print (nametonumber(a))
>> >> >>
>> >> >> Please
>> >> >
>> >> >Your code here is actually pretty close to a correct answer. Just a few things to consider...
>> >> >
>> >> >- Why are you converting your name string to a list? It is unnecessary. When you do "for y in <some string>", then y will still be single characters on each iteration of the loop.
>> >> >
>> >> >- "if y in string.digits" should work fine.
>> >> >
>> >> >- "if y in list(range(1,10)" won't work for two reasons: First, it creates a list of numbers, not strings. Second, even if it did, it would be missing the "0" digit.
>> >> >
>> >> >- At the end, when you convert your list to a string, you don't need to use list comprehension, since nx is already a list. number = "".join(nx) should work fine.
>> >> >
>> >> >Also, in general, you need to stop and slow down and think like a programmer. If you get an error, your instinct shouldn't be to just hack at it to make the error go away. Look at the error and try to make sense of it. Learn what the error means and try to fix the core problem.
>> >> >
>> >> >And for @#$%'s sake...stop saying "It isn't working" and not elaborating. You've been told by every other post in this thread to show us what you did and what the error was. You've also been told to *NOT* retype what you see and to copy/paste your code and the error because when you make a typo when copying, we might see a problem that doesn't exist and then you just get more confused.
>> >>
>> >> Ok I think I may have the question you guys are looking for.
>> >> I just posted it.
>> >> See above.
>> >>
>> >> But it's still broke. :(
>> >
>> >str(range(10)) doesn't do what you think it does.
>> >
>> >Run 'print(str(range(10)))' and look at what you get.
>>
>> Yeah, I know that. My question is why?
>> The answer was that Python 3 only stores the min and max values but
>> you can still iterate over them.
>> I don't think that means what I think it means.
>
>"You can iterate over them" pretty much just means you can use them as the source of a 'for' loop. But in your case, when you're calling 'for y in str(range(10))', you're not using 'range(10)' as the source of your loop, you're using the result of a str() function call, and you're calling str() on range(), which doesn't return a concrete value in Python 3. If you try to print a range(), you're just getting a string containing your original call to range.
>
>And that's why you're seeing the 1 and a in your output. str(range(10)) returns the string 'range(10)'.
>
>Like I said in a previous post, use 'string.digits'. Try this test code and see what you get:
>
>import string
>name="123-xyz-abc"
>print("string.digits is", string.digits)
>for x in name:
> if x in range(10):
> print ("Range",(x))
> if x in string.digits:
> print ("string.digits",(x))
Your example works.
With range(10) you don't expect to see an "a" either.
Thanks
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2014-10-24 21:19 +0000 |
| Subject | Re: I am out of trial and error again Lists |
| Message-ID | <m2efoq$mv8$4@dont-email.me> |
| In reply to | #79598 |
On Fri, 24 Oct 2014 14:15:13 -0400, Seymore4Head wrote: > I do understand that. 7 is a number and "7" is a string. > What my question was...and still is...is why Python 3 fails when I try > using y=1 800 get charter > > y in range str(range(10)) > should work because y is a string and str(range(10)) should be "y" in > str(1) fails. > It doesn't give an error it's just not True when y is a number. This is because str(range(10)) does not do what you think it does. In python 2.x, str(range(10)) creates a string representation of the complete list, not a list of the string representation of the separate list elements. '[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]' In python 3.x, str(range(10)) creates a string representation of the list object. 'range(0, 10)' the only single digit strings in the python3 representation are "0" and "1" To recreate the python2 behaviour in python 3, use: str(list(range(10))) which gives '[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]' howver the test: if x.isdigit(): is much better. But finally, with your telephone number decoder, look at: http://www.codeskulptor.org/#user38_QnR06Upp4AH6h0Q.py -- Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | Seymore4Head <Seymore4Head@Hotmail.invalid> |
|---|---|
| Date | 2014-10-24 17:35 -0400 |
| Subject | Re: I am out of trial and error again Lists |
| Message-ID | <41hl4a1va2dafjtm8gi8q9diknn484dnje@4ax.com> |
| In reply to | #79619 |
On Fri, 24 Oct 2014 21:19:22 +0000 (UTC), Denis McMahon <denismfmcmahon@gmail.com> wrote: >On Fri, 24 Oct 2014 14:15:13 -0400, Seymore4Head wrote: > >> I do understand that. 7 is a number and "7" is a string. >> What my question was...and still is...is why Python 3 fails when I try >> using y=1 800 get charter >> >> y in range str(range(10)) >> should work because y is a string and str(range(10)) should be "y" in >> str(1) fails. >> It doesn't give an error it's just not True when y is a number. > >This is because str(range(10)) does not do what you think it does. > >In python 2.x, str(range(10)) creates a string representation of the >complete list, not a list of the string representation of the separate >list elements. '[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]' > >In python 3.x, str(range(10)) creates a string representation of the list >object. 'range(0, 10)' > >the only single digit strings in the python3 representation are "0" and >"1" > >To recreate the python2 behaviour in python 3, use: > >str(list(range(10))) > >which gives > >'[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]' > >howver the test: > >if x.isdigit(): > >is much better. > >But finally, with your telephone number decoder, look at: > >http://www.codeskulptor.org/#user38_QnR06Upp4AH6h0Q.py That is much cleaner than mine. Nice. I did make one more change to mine that makes it easier to read. I changed treating all " -()" With a space. I am still thinking about how to treat the large space if it is a digit instead: 1 800 555 5555
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2014-10-24 23:23 +0000 |
| Subject | Re: I am out of trial and error again Lists |
| Message-ID | <m2en1u$mv8$10@dont-email.me> |
| In reply to | #79620 |
On Fri, 24 Oct 2014 17:35:34 -0400, Seymore4Head wrote: >>But finally, with your telephone number decoder, look at: >> >>http://www.codeskulptor.org/#user38_QnR06Upp4AH6h0Q.py > > That is much cleaner than mine. Nice. > > I did make one more change to mine that makes it easier to read. I > changed treating all " -()" With a space. > I am still thinking about how to treat the large space if it is a digit > instead: > 1 800 555 5555 Note that my decoder assumes anything other than a letter can be copied straight to the output string. -- Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2014-10-25 14:37 -0400 |
| Subject | Re: I am out of trial and error again Lists |
| Message-ID | <mailman.15170.1414262235.18130.python-list@python.org> |
| In reply to | #79598 |
On Fri, 24 Oct 2014 14:15:13 -0400, Seymore4Head
<Seymore4Head@Hotmail.invalid> declaimed the following:
>
>I do understand that. 7 is a number and "7" is a string.
>What my question was...and still is...is why
>Python 3 fails when I try using
>y=1 800 get charter
>
>y in range str(range(10))
Really... Did you try at an interpreter prompt?
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\Wulfraed\Documents>python3
ActivePython 3.3.2.0 (ActiveState Software Inc.) based on
Python 3.3.2 (default, Sep 16 2013, 23:11:39) [MSC v.1600 64 bit (AMD64)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> y=1 800 get charter
File "<stdin>", line 1
y=1 800 get charter
^
SyntaxError: invalid syntax
>>> y = "1 800 get charter"
>>>
>>> y in range str(range(10))
File "<stdin>", line 1
y in range str(range(10))
^
SyntaxError: invalid syntax
>>>
>should work because y is a string and str(range(10)) should be
Yes... BUT:
>>> y in str(range(10))
False
>>> str(range(10))
'range(0, 10)'
>>> "1 800 get charter" in "range(0, 10)"
False
>>>
>>> "1 800 get charter" in "call 1 800 get charter now to get robbed"
True
>>> y in "call 1 800 get charter now to get robbed"
True
>>>
>"y" in str(1) fails.
>It doesn't give an error it's just not True when y is a number.
>
"y" is not a number, and neither is what you have on the right side.
You are asking if a string appears somewhere inside another string.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2014-10-24 19:33 +0100 |
| Subject | Re: I am out of trial and error again Lists |
| Message-ID | <mailman.15144.1414175621.18130.python-list@python.org> |
| In reply to | #79583 |
On 24/10/2014 18:03, Seymore4Head wrote: > > Actually I was a little frustrated when I added that line back in as > the other lines all work. > Using list(range(10)) Doesn't throw an error but it doesn't work. > > http://i.imgur.com/DTc5zoL.jpg > > The interpreter. I don't know how to use that either. > You've stated that you can use google so why not try it to find out about the interpreter? Or simply navigate to docs.python.org and see what the contents or index tell you? Failing that carry on charging around like a headless chicken and hope that the extremely patient folk here keep helping you out. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | Rustom Mody <rustompmody@gmail.com> |
|---|---|
| Date | 2014-10-24 09:54 -0700 |
| Message-ID | <526127b6-4f00-4040-9c11-6fc172bce952@googlegroups.com> |
| In reply to | #79578 |
Totally befuddled myself! Are you deliberately misspelling list to lst and hoping the error will go away. And Puh LEESE dont post screen shots of good ol ASCII text
[toc] | [prev] | [next] | [standalone]
| From | Seymore4Head <Seymore4Head@Hotmail.invalid> |
|---|---|
| Date | 2014-10-24 13:04 -0400 |
| Message-ID | <9k1l4a13av05ejjjpl319onkrgi37qma22@4ax.com> |
| In reply to | #79581 |
On Fri, 24 Oct 2014 09:54:23 -0700 (PDT), Rustom Mody <rustompmody@gmail.com> wrote: >Totally befuddled myself! > >Are you deliberately misspelling list to lst >and hoping the error will go away. > >And Puh LEESE >dont post screen shots of good ol ASCII text I didn't do that on purpose. I make a lot of typing mistakes. Sorry
[toc] | [prev] | [next] | [standalone]
| From | Rustom Mody <rustompmody@gmail.com> |
|---|---|
| Date | 2014-10-24 10:17 -0700 |
| Message-ID | <4dc5a4e8-4001-4628-be75-1e137739bfab@googlegroups.com> |
| In reply to | #79585 |
On Friday, October 24, 2014 10:37:45 PM UTC+5:30, Seymore4Head wrote: > On Fri, 24 Oct 2014 09:54:23 -0700 (PDT), Rustom Mody wrote: > > >Totally befuddled myself! > > > >Are you deliberately misspelling list to lst > >and hoping the error will go away. > > > >And Puh LEESE > >dont post screen shots of good ol ASCII text > > I didn't do that on purpose. I make a lot of typing mistakes. > Sorry Right No sweat! I was genuinely asking: - Did you mis-spell list as lst? - Or did you go thrashing (Steven gave a picturesque description) just changing things until the error went? [Believe you me, I do the same when I am in a strange place and I am searching for something in my (suit|brief)case ]
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2014-10-24 18:09 -0400 |
| Message-ID | <mailman.15147.1414188396.18130.python-list@python.org> |
| In reply to | #79585 |
Seymore4Head <Seymore4Head@Hotmail.invalid> Wrote in message: > On Fri, 24 Oct 2014 09:54:23 -0700 (PDT), Rustom Mody > <rustompmody@gmail.com> wrote: > >>Totally befuddled myself! >> >>Are you deliberately misspelling list to lst >>and hoping the error will go away. >> >>And Puh LEESE >>dont post screen shots of good ol ASCII text > > I didn't do that on purpose. I make a lot of typing mistakes. > Sorry > That's what copy/paste are for. Copy from your console, and paste into your email. Don't ever retype unless you're trying to frustrate us, -- DaveA
[toc] | [prev] | [next] | [standalone]
| From | Seymore4Head <Seymore4Head@Hotmail.invalid> |
|---|---|
| Date | 2014-10-24 18:27 -0400 |
| Message-ID | <4hkl4app29cjecaiadi9fe6e8tgttl3os6@4ax.com> |
| In reply to | #79623 |
On Fri, 24 Oct 2014 18:09:59 -0400 (EDT), Dave Angel <davea@davea.name> wrote: >Seymore4Head <Seymore4Head@Hotmail.invalid> Wrote in message: >> On Fri, 24 Oct 2014 09:54:23 -0700 (PDT), Rustom Mody >> <rustompmody@gmail.com> wrote: >> >>>Totally befuddled myself! >>> >>>Are you deliberately misspelling list to lst >>>and hoping the error will go away. >>> >>>And Puh LEESE >>>dont post screen shots of good ol ASCII text >> >> I didn't do that on purpose. I make a lot of typing mistakes. >> Sorry >> > >That's what copy/paste are for. Copy from your console, and paste > into your email. Don't ever retype unless you're trying to > frustrate us, I promise I am not trying to frustrate anyone. I know I have. Sorry
[toc] | [prev] | [next] | [standalone]
| From | Rustom Mody <rustompmody@gmail.com> |
|---|---|
| Date | 2014-10-24 16:01 -0700 |
| Message-ID | <c2cfe605-4697-4264-9f7f-dd2a445f869b@googlegroups.com> |
| In reply to | #79626 |
On Saturday, October 25, 2014 4:00:01 AM UTC+5:30, Seymore4Head wrote: > On Fri, 24 Oct 2014 18:09:59 -0400 (EDT), Dave Angel wrote: > > Don't ever retype unless you're trying to > > frustrate us, > > I promise I am not trying to frustrate anyone. I know I have. > Sorry No issues Seymore :-) As far as I am concerned this has been useful and educative for me -- I found out about codeskulptor. Though I am a bit conflicted whether it helps or confuses students. Also many other things... What I take as minor distinctions between python 2 and 3 may not be so minor if one doesn't know whats going on.
[toc] | [prev] | [next] | [standalone]
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2014-10-24 20:27 -0400 |
| Message-ID | <mailman.15150.1414196852.18130.python-list@python.org> |
| In reply to | #79626 |
On 10/24/2014 6:27 PM, Seymore4Head wrote: > I promise I am not trying to frustrate anyone. I know I have. Seymore, if you want to learn real Python, download and install 3.4.2 and either use the Idle Shell and Editor or the interactive console interpreter and a decent programmer editor. I cannot recommend CodeSkulptor to anyone. The opening statement # CodeSkulptor runs Python programs is deceptive. CodeSkulptor Python is not Python. It does not correspond to any x.y version of Python. It is a somewhat crippled subset of ancient Python (2.1) with selected additions of later features. It does not have exceptions, raise, and try: except:. These are an essential part of original Python and Python today It does not have complex (maybe introduced in 1.5) and unicode (introduced in 2.0). Let that pass. More important, it does not have new-style classes, an essential new feature introduced in 2.2. Python beginners should start with unified new-styled classes. If lucky, they need never learn about the original old style, dis-unified type versus class system that started going away in 2.2, is mostly gone in 2.7. and completely gone in 3.0. If you really want to continue with CodeSkulpter Python, you should find a CodeSkulpterPython list. You cannot expect people here to know that legal code like class I(int): pass will not run, but will fail with an exceeding cryptic message: Line 1: undefined: TypeError: a.$d is undefined Nor can you expect us to know all the other limitations. This is a list for Python. If you want help here, get and use a real Python interpreter, with a proper interactive mode, as multiple people have suggested. -- Terry Jan Reedy
[toc] | [prev] | [next] | [standalone]
Page 4 of 8 — ← Prev page 1 2 3 [4] 5 6 7 8 Next page →
Back to top | Article view | comp.lang.python
csiph-web