Skip to content

Instantly share code, notes, and snippets.

@horvatha
Last active December 2, 2016 21:59
Show Gist options
  • Save horvatha/47c839b7fc4ba51ef1d2a9a56168a002 to your computer and use it in GitHub Desktop.
Save horvatha/47c839b7fc4ba51ef1d2a9a56168a002 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python3
def main():
with open("egyketto.txt") as f:
sorok = f.readlines()
print("".join([s for s in szures(sorok, "POST Data", "New host")]))
def szures(sorok, pluszegyes, sima):
kimeno_sorok = []
ennyi_sort_meg = 0
add_hozza_a_sort = False
for sor in sorok:
if pluszegyes in sor:
add_hozza_a_sort = True
ennyi_sort_meg = 2
if sima in sor:
add_hozza_a_sort = True
if add_hozza_a_sort or ennyi_sort_meg > 0:
kimeno_sorok.append(sor)
add_hozza_a_sort = False
ennyi_sort_meg -= 1
return kimeno_sorok
# Tesztelés
szoveg = """
egy
ketto
1 x
2 x
3 x
egy
1 y
2 y
3 y
ketto
1 z
2 z
3 z
ketto
egy
1 w
2 w
3 w
"""
def tests():
sorok = szoveg.splitlines()
print(szures(sorok, "egy", "ketto"))
if __name__ == "__main__":
main()
POST Data
New host
1 x
2 x
3 x
POST Data
1 y
2 y
3 y
New host
1 z
2 z
3 z
New host
POST Data
1 w
2 w
3 w
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment