Last active
August 29, 2015 14:04
-
-
Save mynameisfiber/9a0902b22da2d5f409f8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Why does this work | |
| def split_chars(words, chars): | |
| itr = (words,) | |
| for c in chars: | |
| itr = tuple(chunk for word in itr for chunk in word.split(c)) | |
| return list(itr) | |
| # but this not work | |
| def split_chars_broken(words, chars): | |
| itr = (words,) | |
| for c in chars: | |
| itr = (chunk for word in itr for chunk in word.split(c)) | |
| return list(itr) | |
| >>> split_chars("assdf,asdfadsf.sadfadsf,asdf.asdf", ".,") | |
| ['assdf', 'asdfadsf', 'sadfadsf', 'asdf', 'asdf'] | |
| >>> split_chars_broken("assdf,asdfadsf.sadfadsf,asdf.asdf", ",.") | |
| ['assdf,asdfadsf', 'sadfadsf,asdf', 'asdf'] | |
| >>> split_chars_broken("assdf,asdfadsf.sadfadsf,asdf.asdf", ".,") | |
| ['assdf', 'asdfadsf.sadfadsf', 'asdf.asdf'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment