<div dir="ltr">Hi,<br><div class="gmail_extra"><br><br><div class="gmail_quote">On 28 October 2013 20:55, Alex Tenno <span dir="ltr"><<a href="mailto:alex.tenno@gmail.com" target="_blank">alex.tenno@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hey everyone,<div><br></div><div>I'm encountering a problem with a python function that I am supposed to create. </div>
</div></blockquote><div><br></div><div>OK. You should try to actually write the function yourself first, then give concrete details about what you've tried, and how you're stuck. <br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div>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'. </div>
</div></blockquote><div><br></div><div>Is this the exact problem statement or are you paraphrasing? I'd like to make sure I understand the question. <br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div>I have been given hints that tell me "<span style="font-size:13px;font-family:Arial">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.</span></div>
</div></blockquote><div><br></div><div>OK so you've been given some high level idea of what to do. Try to break this down to more concrete steps, perhaps firstly still only pseudocode, and eventually translate that to Python. <br>
<br>The idea embodied in the suggestion is based on the observation that you can determine the relative position in the alphabet, of each character in the word by, looking the letter in the word, and then counting how many /distinct/ letters in the word are smaller than or equal to the letter under scrutiny. For the smallest letter, this will by definition only count the letter itself (if you compare with every distinct letter in the word), resulting in a count of 1. For the second smallest letter, this will therefore result in the smallest letter and the 2nd smallest letter being counted, resulting in a count of 2. And so on. These counts then give the relative position of each letter in the alphabet. Amit's suggestion boils down to the same idea -- sort the set of distinct letters in the string, and then look up the relative position of each letter in your original string in this sorted set. Next questions to think about: How do you calculate the set of distinct letters in the string? (Hint: Look at set() function.) How do you calculate the count of smaller letters from this distinct set? (Hint: Loop over the set and count as you go.) Or convert this set to a sorted list to then lookup against. (Hint: Look at the list() function and the sorted() function.)<br>
<br>Walter<br></div><div><br></div><div><br></div><div> </div></div></div></div>