0

I'm writing a script like the following:

In the input for text, I'll write a word, and if the letter in that word is abcde it will just print the letter, else its going to print the letter + oand then the letter again.

For the result right now, I get (for example the text = allan), "a lil lil a nin".

I want the result to be: "alillilanin".

How do I remove the whitespace?

def sprak(text):
    bok = "abcde"
    for letter in text:   
        if letter in bok == bok:
            print letter,
        elif letter != bok:
            print letter+"u"+letter,


text = raw_input("what word ")
sprak(text)
Kara
  • 6,115
  • 16
  • 50
  • 57
  • What does `if letter in bok == bok:` mean to you? I'm not convinced it would mean the same to Python. – johnsyweb Nov 26 '13 at 13:07
  • Please edit your question: the example you give does not match your code. – Jan Doggen Nov 26 '13 at 13:09
  • ye nevermind dont know what i did there, removed the last "== bok" part, so its now if letter in bok: – user3036505 Nov 26 '13 at 13:11
  • 3
    @user3036505 Instead of editing your post to note the problem is solved, could you [mark the answer that helped you (if one did) as accepted](http://stackoverflow.com/help/accepted-answer)? – thegrinner Nov 26 '13 at 14:15

3 Answers3

1

Just do not use print, try this:

def sprak(text):
    bok = "abcde"
    for letter in text:   
        if letter in bok == bok:
            sys.stdout.write(letter)
        elif letter != bok:
            sys.stdout.write(letter + "u" + letter)
Adriano Repetti
  • 65,416
  • 20
  • 137
  • 208
0

You would need Python v3 print function for that. You would need to import that function first by

from __future__ import print_function

Now, to suppress the whitespace separator between items.

print(letter + 'u' + letter, sep='')

& to also suppress the endline terminator do

print(letter, sep='', end='')
shad0w_wa1k3r
  • 12,955
  • 8
  • 67
  • 90
0

Construct a string and print once:

output_str = ''
for letter in text:   
    if letter in bok == bok:
        output_str += letter,
    elif letter != bok:
        output_str += letter+"u"+letter
print output_str
jpwagner
  • 553
  • 2
  • 8