Skip to content

Instantly share code, notes, and snippets.

@costastf
Created December 22, 2020 14:06
Show Gist options
  • Save costastf/8c3cd54877948edbaeafea7424335c09 to your computer and use it in GitHub Desktop.
Save costastf/8c3cd54877948edbaeafea7424335c09 to your computer and use it in GitHub Desktop.
def split_element(input, index, splitting_character=' '):
# we don't accept to split on more than one character and check for length of list
if any([index > len(input), len(splitting_character) > 1]):
return input
# if splitting character is no character we default to a space
items = input[index].split(splitting_character or ' ')
# if we actually have items are remove the inital from the list and insert our elements
if len(items) > 1:
input.pop(index)
for count_, item in enumerate(items):
input.insert(index + count_, item)
return input
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment