[Tutor] Python String Help

Amit Saha amitsaha.in at gmail.com
Tue Oct 29 10:42:28 CET 2013


On Oct 29, 2013 7:18 PM, "Alex Tenno" <alex.tenno at gmail.com> wrote:
>
> Hey everyone,
>
> I'm encountering a problem with a python function that I am supposed to
create. I want my function to look at a string, and then replace each
letter in the string with its relative position in the alphabet. for
example, 'abcde' would return '12345', 'zabd' would return '4123', and
'xpft' would return '4213'. I have been given hints that tell me "You may
want to iterate over the letters ch in s as in the for loop above, and
inside that for loop, count the number of letters that are in s and come
before the loop variable ch. You will also need an accumulator to build the
permutation the function will return." any help would be greatly
appreciated.

Have you thought on the lines of sorting the string and checking what
position each letter of the original string is in the sorted string?

For eg. 'zabd' sorted would be 'abdz' and you can check which position 'z'
is in and so on.

Hope that helps.
Best,
Amit.
>
> Many thanks!
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20131029/f9159748/attachment.html>


More information about the Tutor mailing list