Created
April 19, 2018 09:49
-
-
Save canwe/ec9fa2e355096296f0b70ef3370a1124 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
import collections | |
import copy | |
s = "I am a test sentence and I am very cute." | |
s_list = s.split() | |
s_list_backup = copy.deepcopy(s_list) | |
[s_list.remove(item) for item in s_list_backup if item in ',.!"'] | |
print(collections.Counter(s_list)) | |
s_list = s.split() | |
for item in s_list: | |
if item.strip() not in ',.!"': | |
if item not in s_dict: | |
s_dict[item] = 1 | |
else: | |
s_dict[item] += 1 | |
print(s_dict) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment