Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def find_positive_magic_integer(file):
- start_chars = [
- *map(chr, range(ord('a'), ord('z') + 1)),
- *map(chr, range(ord('A'), ord('Z') + 1)),
- '_'
- ]
- res = {}
- with open(file, 'r') as infile:
- for i, line in enumerate(infile.read().splitlines(), 1):
- elems = line.split()
- if not (len(elems) == 3 and elems[0][0] in start_chars
- and elems[-1].isdigit() and line == ' '.join(elems)):
- for elem in elems:
- if elem.isdigit() and int(elem) > 1 and i not in res.get(elem, []):
- res.setdefault(elem, []).append(i)
- return res
- def fucking_find_positive_magic_integer(file):
- res = {}
- list(filter(lambda y:
- list(filter(lambda t: t.isdigit() and int(t) > 1
- and y[0] not in res.get(t, [])
- and res.setdefault(t, []).append(y[0]),
- y[1].split())),
- filter(lambda x:
- not (len(x[1].split()) == 3 and x[1].split()[0][0] in [
- *map(chr, range(ord('a'), ord('z') + 1)),
- *map(chr, range(ord('A'), ord('Z') + 1)),
- '_'
- ] and x[1].split()[-1].isdigit()
- and x[1] == ' '.join(x[1].split())),
- enumerate(open(file, 'r').read().splitlines(), 1))
- ))
- return res
- if __name__ == '__main__':
- print(find_positive_magic_integer("./magic_number_test1.py"))
- print(fucking_find_positive_magic_integer("./magic_number_test1.py"))
- print(find_positive_magic_integer("./magic_number_test2.py"))
- print(fucking_find_positive_magic_integer("./magic_number_test2.py"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement