I am out of trial and error again Lists

Seymore4Head Seymore4Head at Hotmail.invalid
Fri Oct 24 12:37:32 EDT 2014


On Fri, 24 Oct 2014 08:56:31 -0700 (PDT), Rustom Mody
<rustompmody at gmail.com> wrote:

>On Friday, October 24, 2014 8:11:12 PM UTC+5:30, Seymore4Head wrote:
>> On Thu, 23 Oct 2014 21:56:31 -0700 (PDT), Rustom Mody 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))
>
><Other details skipped>
>
>> 
>> 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.
>
>I asked you to try
>list(range(10))
>
>Did you try EXACTLY (cut-paste) that?
>
>You are claiming to have tried
>list(range(10)
>
>Thats one closing parenthesis less
>
>The interaction with your version would go something like this:
>[Two versions 
>The KeyboardInterrupt comes from giving a control-C
>Dunno what happens in codeskulptor
>]
>
>>>> list(range(10)
>... 
>... 
>... 
>... )
>[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>>> list(range(10)
>... 
>KeyboardInterrupt
>
>
>> 
>> Thanks everyone for your suggestions.
>
>1. You are reading too much
>2. Trying tooooo hard
>
>Think of riding a bicycle.
>Cant do it by reading many books on cycling -- thats 1.
>Nor by holding the handle so hard you tremble -- thats 2.
>
>Just relax a bit...
>And take small steps
>
>Chill... as Chris joked, no monster in the computer (or on this list!)
>
>
>> Range(10) stores the min max values and loads each number in between
>> when needed.
>
>It loads?? As in 'load-up-a-van'??
>
>When you see:
>
>>>> 10
>10
>
>1. Does someone (a clerk maybe) in the computer count to 10?
>2. Or do you, seeing that interaction, count to 10?
>   [If you do, replace the 10 by 1000]
>3. Or do you, remember what it means to count to 10 without having to do it?
>
>Now go back to your statement about 'loading' and find a better verb

If I could explain to you why something doesn't work then I could fix
it myself.  I don't understand why it doesn't work.  The best I can do
is repost the code. 

When I use list(range(10)) I get:
Traceback (most recent call last):
  File "C:/Functions/name to number digit.py", line 37, in <module>
    print (nametonumber(a))#1800 438 2427 837
  File "C:/Functions/name to number digit.py", line 10, in
nametonumber
    if y in lst(range(1,10)):
TypeError: 'list' object is not callable

All the lines I have commented out work.  Trying to use
list(range(10)) doesn't.  (Python 3)
http://i.imgur.com/LtiCyZS.jpg

It doesn't work.
It's broke.  :)
I don't know what else to say.

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 lst(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))

BTW thanks again for all the help



More information about the Python-list mailing list