Skip to content

Instantly share code, notes, and snippets.

@fnx4
Last active May 21, 2020 22:43
Show Gist options
  • Save fnx4/4c2409a156a37df401348e60d1accede to your computer and use it in GitHub Desktop.
Save fnx4/4c2409a156a37df401348e60d1accede to your computer and use it in GitHub Desktop.
import re
with open('input.txt') as f:
a = f.read()
arr = list()
# verb ambush /ˈæˌmbʊʃ/ находиться, сидеть в засаде 1. Wait in hiding to attack. Syn: scupper, bushwhack, waylay, ... 2. Hunt (quarry) by stalking and ambushing. Syn: still-hunt.
# noun ambush /ˈæˌmbʊʃ/ засада The act of concealing yourself and lying in wait to attack by surprise. Syn: ambuscade, lying in wait, trap.
for line in a.split('\n'):
arr.append(re.split(r'\t+', line))
# 0 1 2 3 4
# ['verb', 'ambush', '/ˈæˌmbʊʃ/', 'находиться, сидеть в засаде', '1. Wait in hiding to attack. Syn: scupper, bushwhack, waylay, ... 2. Hunt (quarry) by stalking and ambushing. Syn: still-hunt.']
# ['noun', 'ambush', '/ˈæˌmbʊʃ/', 'засада', 'The act of concealing yourself and lying in wait to attack by surprise. Syn: ambuscade, lying in wait, trap.']
res = {}
for cw in arr:
if cw[1] in res:
res[cw[1]][0] += ", " + cw[0]
res[cw[1]][1] = cw[1]
if res[cw[1]][2] != cw[2]:
res[cw[1]][2] += "<br/>" + cw[2]
if len(cw) == 5:
res[cw[1]][3] += " / " + cw[3]
res[cw[1]][4] += "<br/>" + cw[0] + ": " + cw[4]
else:
if len(cw) == 5:
res[cw[1]] = [cw[0], cw[1], cw[2], cw[3], cw[0] + ": " + cw[4]]
else:
res[cw[1]] = [cw[0], cw[1], cw[2]]
# 0 'verb, noun',
# 1 'ambush',
# 2 '/Л€Г¦ЛЊmbКЉКѓ/',
# 3 'находиться, сидеть в засаде / засада',
# 4 'verb: 1. Wait in hiding to attack. Syn: scupper, bushwhack, waylay, ... 2. Hunt (quarry) by stalking and ambushing. Syn: still-hunt.<br/>
# noun: The act of concealing yourself and lying in wait to attack by surprise. Syn: ambuscade, lying in wait, trap.'
out = ""
for i in res.values():
if i[1] == "bid":
print()
try:
if len(i) != 3:
out += "<p style='display:inline;color:black'>" + i[1] + "</p> " \
+ "<p style='display:inline;color:gray'>(" + i[0] + ")</p>\t" \
+ "<b style='display:inline;color:blue' >" + i[3] + "</b><br/><br/>" \
+ "<p style='display:inline;color:black'>" + i[2] + "</p><br/><br/>" \
+ "<p style='display:inline;color:green'>" + i[4] + "</p><br/><br/>\n"
else:
out += "<p style='display:inline;color:black'>" + i[1] + "</p> " \
+ "<p style='display:inline;color:gray'>(" + i[0] + ")</p>\t" \
+ "<b style='display:inline;color:blue' >" + i[2] + "</b>\n"
except:
print("exception, input: " + str(i))
continue
print(out)
# <p style='display:inline;color:black'>ambush</p>
# <p style='display:inline;color:gray'>(verb, noun)</p>
# <b style='display:inline;color:blue' >
# находиться, сидеть в засаде / засада
# </b>
# <br/><br/>
# <p style='display:inline;color:black'>
# /Л€Г¦ЛЊmbКЉКѓ/
# </p>
# <br/><br/>
# <p style='display:inline;color:green'>
# verb: 1. Wait in hiding to attack. Syn: scupper, bushwhack, waylay, ... 2. Hunt (quarry) by stalking and ambushing. Syn: still-hunt.<br/>
# noun: The act of concealing yourself and lying in wait to attack by surprise. Syn: ambuscade, lying in wait, trap.
# </p>
# <br/><br/>
with open('output.html', 'w') as ouf:
ouf.write(out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment