Created
May 31, 2013 23:51
-
-
Save sagivmalihi/5688701 to your computer and use it in GitHub Desktop.
Can you spot the bug?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
def expand_letters(word, times): | |
expanded_letters = [] | |
for letter in word: | |
expanded_letters.append( (letter for _ in xrange(times)) ) | |
return ''.join(itertools.chain.from_iterable(expanded_letters)) | |
print expand_letters("Hello", 2) |
@btv - This is just an abridged version of a bug I had (and fixed actually, now I'm just ranting...)
The output here, instead of the expected 'HHeelllloo' is actually 'oooooooooo' - Guess why ;)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So many things that don't make sense with this... what are you trying to accomplish? Maybe I can help.
Since you're aware of the itertools module, why didn't you use repeat instead of:
(letter for _ in xrange(times))
http://docs.python.org/2/library/itertools.html#itertools.repeat