On Fri, 24 Oct 2014 21:19:22 +0000 (UTC), Denis McMahon <denismfmcma...@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 -- https://mail.python.org/mailman/listinfo/python-list