Skip to content

Instantly share code, notes, and snippets.

@renzon
Forked from dubirajara/string_n_string.py
Last active January 3, 2019 12:23
Show Gist options
  • Save renzon/e2da1c50d914909427f51d4993e94e87 to your computer and use it in GitHub Desktop.
Save renzon/e2da1c50d914909427f51d4993e94e87 to your computer and use it in GitHub Desktop.
String -> N iterations -> String created by dubirajara1 - https://repl.it/@dubirajara1/String-greater-N-iterations-greater-String
from itertools import chain
def string_n_string(s, n):
for _ in range(n):
even = (char for i, char in enumerate(s) if i % 2 == 0)
odd = (char for i, char in enumerate(s) if i % 2 != 0)
s = ''.join(chain(even , odd))
return s
assert string_n_string("Wow Example!", 1) == "WwEapeo xml!" # testcase
assert string_n_string("qwertyuio", 2) == "qtorieuwy" # testcase
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment