尽管模块按预期工作,但我每次都会收到以下警告:
/usr/local/lib/python3.7/site-packages/grequests.py:21: MonkeyPatchWarning: Monkey-patching ssl after ssl has already been imported may lead to errors, including RecursionError on Python 3.6. It may also silently lead to incorrect behaviour on Python 3.7. Please monkey-patch earlier. See https://github.com/gevent/gevent/issues/1016. Modules that had direct imports (NOT patched): ['urllib3.util (/usr/local/lib/python3.7/site-packages/urllib3/util/__init__.py)', 'urllib3.contrib.pyopenssl (/usr/local/lib/python3.7/site-packages/urllib3/contrib/pyopenssl.py)'].
curious_george.patch_all(thread=False, select=False)
Run Code Online (Sandbox Code Playgroud)
我尝试了这个 github 问题中提到的解决方法,但这不起作用。
如何摆脱这个警告?
我有一个看起来像这样的列表:
my_list = ['singapore','india','united states','london','paris','india','london','china','singapore','singapore','new york']
Run Code Online (Sandbox Code Playgroud)
现在,我Counter[dict]
只需要此列表中的特定单词
Counter(my_list) gives me the following :
Counter({'singapore': 3, 'india': 2, 'london': 2, 'united states': 1, 'paris': 1, 'china': 1, 'new york': 1})
Run Code Online (Sandbox Code Playgroud)
但是有没有一种方法可以创建仅包含列表中特定单词的计数器,例如, ['london','india','singapore']
最快的方法是什么?我的清单很大。
我试过的:my_list.count('london')
例如。但是,有没有更快的方法来实现这一目标?