Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def escaped_split(s, delim, escape='\\'):
- ret = []
- current = []
- itr = iter(s)
- for ch in itr:
- if ch == escape:
- try:
- nextCh = next(itr)
- if nextCh not in delim:
- current.append(escape)
- current.append(nextCh)
- except StopIteration:
- current.append(escape)
- elif ch in delim:
- ret.append(''.join(current))
- current = []
- else:
- current.append(ch)
- ret.append(''.join(current))
- return ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement