Created
February 14, 2020 10:25
-
-
Save hiepph/2f0d5296e97b109031802249b89b01cf to your computer and use it in GitHub Desktop.
Weird functional python
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
from toolz import * | |
from toolz.curried import * | |
import string | |
lines = open('./gt.txt').readlines() | |
imgs = pipe( | |
lines, | |
map(lambda l: l.split('\t')[0]), | |
list | |
) | |
labels = pipe( | |
lines, | |
map(lambda l: l.strip().lower().split('\t')[1]), | |
map(lambda s: s.replace(chr(8203), '')), | |
list | |
) | |
filtered = pipe( | |
zip(imgs, labels), | |
filter(lambda x: all(map(lambda c: c not in string.ascii_lowercase, x[1] ))), | |
list | |
) | |
with open('./_gt.txt', 'w') as f: | |
for img, label in filtered: | |
f.write(f'{img}\t{label}\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment