Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- def fancy_split(s):
- return re.findall(r'[^",]+|"(?:[^\"]|\")*"', s)
- test_cases = [
- ("a,b,c", ["a", "b", "c"]),
- ('a,"b,c"', ["a", '"b,c"']),
- ('a,"b\\",\\"c"', ["a", '"b\\",\\"c"']),
- ("a,,b", ["a", "", "b"])
- ]
- for input, expected_output in test_cases:
- actual_output = fancy_split(input)
- print(input)
- print(f" {expected_output!r}")
- print(f" {actual_output!r}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement