Skip to content

Instantly share code, notes, and snippets.

@villares
Created September 30, 2021 13:46
Show Gist options
  • Save villares/21d395ea7f55d51aded3c4dfa5036066 to your computer and use it in GitHub Desktop.
Save villares/21d395ea7f55d51aded3c4dfa5036066 to your computer and use it in GitHub Desktop.
splitting duos
names = ['Albert', 'Allison & Peter', 'John & Paul', 'Mary', 'Ann']
def r_enumerate(iterable):
return reversed(tuple(enumerate(iterable)))
for i, name in r_enumerate(names):
if '&' in name:
a, b = name.split('&')
names[i] = a.strip()
names.insert(i + 1, b.strip())
print(names)
# result printed:
# ['Albert', 'Allison', 'Peter', 'John', 'Paul', 'Mary', 'Ann']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment