Last active
August 2, 2020 17:13
-
-
Save udomsak/5fbdf839d0d7158e3643df815519c693 to your computer and use it in GitHub Desktop.
community answer | Python Thailand
This file contains 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
#%% md | |
For sharing challenge. in python-thailand. | |
#%% md | |
Quest: https://www.facebook.com/groups/admin.py.dev/permalink/1419625491555983/ | |
Doc: https://docs.python.org/3/library/re.html | |
#%% | |
import re | |
test_data = ''' | |
"THB": "32.202083200" | |
"THB": "33.029302029020" | |
"THB": "34.20293020" | |
''' | |
regex = re.compile(r'([0-9.]*[0-9])') | |
for item in test_data.split('\n'): | |
if re.search(regex, item) is not None: | |
capture_float = re.search(regex, item)[0] | |
print("Capture String value from: {} is: {}". | |
format(item, re.search(regex, capture_float)[0])) | |
#%% md | |
Quest: https://www.facebook.com/groups/admin.py.dev/permalink/1414944392024093 | |
docs https://realpython.com/python-histograms/ | |
#%% | |
string_list = ['aa', 'bb', 'cc', 'vv', 'vv', 'bb'] | |
output = dict() | |
for item in string_list: | |
output[item] = output.get(item, 0) + 1 | |
print(output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment