Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2021
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. import re
  2.  
  3. def fancy_split(s):
  4. return re.findall(r'[^",]+|"(?:[^\"]|\")*"', s)
  5.  
  6. test_cases = [
  7. ("a,b,c", ["a", "b", "c"]),
  8. ('a,"b,c"', ["a", '"b,c"']),
  9. ('a,"b\\",\\"c"', ["a", '"b\\",\\"c"']),
  10. ("a,,b", ["a", "", "b"])
  11. ]
  12.  
  13. for input, expected_output in test_cases:
  14. actual_output = fancy_split(input)
  15. print(input)
  16. print(f" {expected_output!r}")
  17. print(f" {actual_output!r}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement