On Fri, 24 Oct 2014 11:57:12 -0700 (PDT), sohcahto...@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.ke...@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.  :( 
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to