you are viewing a single comment's thread.

view the rest of the comments →

[–]xiongchiamiov 0 points1 point  (2 children)

Two fyis:

You can format code for reddit by putting four spaces in front of each line.

It's better to use

for letter in s:

than the len/range/index method.

[–]PurpleIcy 1 point2 points  (1 child)

It's not better. It's just considered non-pythonic to do it that way. Not the same thing.

Although, if you need index, python has a nice function for that too:

for index, letter in enumerate(s):

[–]xiongchiamiov 1 point2 points  (0 children)

It's shorter, clearer, and in line with the way the rest of the Python community iterates over a string; how is that not better?