Skip to content

Instantly share code, notes, and snippets.

@udomsak
Last active August 2, 2020 17:13
Show Gist options
  • Save udomsak/5fbdf839d0d7158e3643df815519c693 to your computer and use it in GitHub Desktop.
Save udomsak/5fbdf839d0d7158e3643df815519c693 to your computer and use it in GitHub Desktop.
community answer | Python Thailand
Display the source blob
Display the rendered blob
Raw
#%% 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