Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>How to slice a string:</p> <pre><code>word = 'these' print word[0] # it's similar to list indexing, starts at 0 </code></pre> <p>To get the letters in backwards order, use a negative number: <code>word[-1]</code> is the last letter; <code>word[-2]</code> is the second to last, etc.</p> <p><code>word[1:]</code> returns every letter from index 1 (the second letter) to the end. 'word[:5]<code>returns every letter up to index 5 (exclusive, letters 1, 2, 3, and 4). </code>words[1:5]` returns every letter from index 1 up to index 5 (letters 2, 3, and 4).</p> <p>Since you have multiple lines, you want to do <code>words += lines.split()</code> because </p> <pre><code>untranslated = open('english.txt','r') vowels = ('a', 'e', 'i', 'o', 'u') # I like using lists/tuples rather than strings # if you are just checking if something is in it newWords = [] for lines in untranslated: words += lines.split() # this fixes the last line problem # this assumes each word is on one line, separated by a space (like: 'these are words') for word in words: # iterates through every word if word[0] in vowels: # if first letter is a vowel new_word = word + 'yay' else: new_word = word[1:] + word[0] + 'ay' newWords.apend(new_word) </code></pre> <p>Based off of Eric Roper's suggestion, you can create a dictionary as a translation:</p> <pre><code>newWords = {} for word in words: if word[0] in vowels: new_word = word + 'yay' newWords[word] = new_word else: new_word = word[1:] + word[0] + 'ay' newWords[word] = new_word </code></pre> <p>Some references:</p> <ul> <li><a href="http://www.tutorialspoint.com/python/python_strings.htm" rel="nofollow">Strings</a></li> <li><a href="http://www.tutorialspoint.com/python/python_dictionary.htm" rel="nofollow">Dictionaries</a></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload