Skip to content

Instantly share code, notes, and snippets.

@sagivmalihi
Created May 31, 2013 23:51
Show Gist options
  • Select an option

  • Save sagivmalihi/5688701 to your computer and use it in GitHub Desktop.

Select an option

Save sagivmalihi/5688701 to your computer and use it in GitHub Desktop.
Can you spot the bug?
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)
@sagivmalihi
Copy link
Author

@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