I am out of trial and error again Lists

Larry Hudson orgnut at yahoo.com
Wed Oct 22 22:58:24 EDT 2014


On 10/22/2014 05:02 PM, Seymore4Head wrote:
> On Thu, 23 Oct 2014 00:44:01 +0100, Mark Lawrence
> <breamoreboy at yahoo.co.uk> wrote:

<snip>  (This is in reference to the line:  if y in str(range(10)):)

>> I suggest you try str(range(10)) from the interactive prompt and see
>> exactly what you get, as it's nothing like what you expect :)
>
> I see that now.  So there may not be a short hand solution.
>

Yes there is.

That statement would work in Py2 as-is, but in Py3 it needs to be changed to:

if y in list(range(10)):

This give you a list not a string, but that's actually what you want here.  If you _really_ want 
a string, use join():  "".join(list(range(10)))

------  Also, from another post:  -------

 > Thanks a lot for all your suggestions.  I haven't learned to use the
 > interpreter yet.  I do plan on learning to use it.

You are making yourself work several hundred times harder if you don't learn to use the 
interactive mode!

 > The problem with that at the moment is that I have enrolled in an
 > online computer class.  They use Codeskulptor.
 > Codeskulptor code is not compatible to standard Python.

I would be GREATLY bothered by the fact that it is not standard Python -- it sounds like a poor 
course.  You also seems to imply that you are only using those on-line tools and don't have a 
real Python installed on your own system.  If so, that is an extremely bad choice.  And if so, 
stop everything until you do install it NOW (definitely Python 3).  Then you can play with 
things on your own system IN THE INTERACTIVE MODE!!!  That's when you will start actually learning.

      -=- Larry -=-




More information about the Python-list mailing list