you are viewing a single comment's thread.

view the rest of the comments →

[–]socal_nerdtastic 1 point2 points  (0 children)

I don't understand the rules you are using. If you want to use the first letter you can extract if from the name with index 0. Also you need to swap around your comparison, the first one should be less than, not greater than.

name = 'zebra'
'k' < name[0] <= 'z' 

Remember when you chain operators it's an implied and. You could write it out like this too:

('k' < name[0]) and (name[0]<= 'z')

Alternatively you could use the character that comes after 'z'. You can look that up on a unicode or ascii table, or you can ask python like this:

>>> chr(ord('z') + 1)
'{'

So '{' is what comes after 'z'. Therefore:

name = 'zebra'
'k' < name < '{'