@SnoopJeDi/

ProfitableRecklessFlashdrives

Python

No description

fork
loading
Files
  • main.py
  • input.txt
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python3
import re

start = '>SHOW ENCLOSURE INFO'
end = '>SHOW ENCLOSURE LED'

# first way, kinda slopppy
with open('input.txt', 'r') as f:
    lines = f.readlines()
    try:
        sidx = next(idx for idx, line in enumerate(lines) if line.startswith(start))
        eidx = next(idx for idx, line in enumerate(lines) if line.startswith(end))
        result = lines[sidx+1:eidx]
    except StopIteration: # one of the index lines failed
        result = 'No result!'

print(*result)

# second way, much nicer!
with open('input.txt', 'r') as f:
    _, _, data = f.read().partition(start)
    result, _, _ = data.partition(end)

print(result)