Skip to content

Instantly share code, notes, and snippets.

@hiepph
Created February 14, 2020 10:25
Show Gist options
  • Save hiepph/2f0d5296e97b109031802249b89b01cf to your computer and use it in GitHub Desktop.
Save hiepph/2f0d5296e97b109031802249b89b01cf to your computer and use it in GitHub Desktop.
Weird functional python
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