# I am out of trial and error again Lists

Denis McMahon denismfmcmahon at gmail.com
Sat Oct 25 01:35:02 CEST 2014

```On Fri, 24 Oct 2014 18:58:04 -0400, Seymore4Head wrote:

> On Wed, 22 Oct 2014 16:30:37 -0400, Seymore4Head

OK, assuming you tried to run this in python3, not python2 or
codeskulptor.

> name="123-xyz-abc"
> a=range(10)

^^^^ a is an iterable object giving the numbers 0 through 9

> b=list(range(10))

^^^^ b is an list containing the numbers 0 through 9

> c=str(list(range(10)))

^^^^ c is an string representation of a list containing the numbers 0
through 9

> print ("a",(a))
> print ("b",(b))
> print ("c",(c))
>
> for x in name:

^^^^^ x is a string representing one character in name

>     if x in a:
>         print ("a",(x))

^^^^ here you are looking for a string x amongst the numbers yielded by
an iterable

>     if x in b:
>         print ("b",(x))

^^^^ here you are comparing a string x with the elements of a list of
numbers

>     if x in c:
>         print ("c",(x))

^^^^ here you are comparing a string x with the characters in a string
representation of a list of numbers

> B is type list and C is type str.
> I guess I am still a little too thick.  I would expect b and c to work.
> http://i.imgur.com/dT3sEQq.jpg

a is the range object: range(0, 9)
b is the list: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
c is the string: "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"

When you try and compare a character x eg "8" with the numbers yielded by
the iterable a, none of them match because character "8" is not the same
as number 8

When you try and compare a character x eg "8" with the elements of the
list b, none of them match because character "8" is not the same as
number 8

When you try and compare a character x eg "8" with the string
representation of the list b, you get a match of x "8" to the 25th
character of string c which is also "8".

--
Denis McMahon, denismfmcmahon at gmail.com

```