Advertisement
shinemic

pos_mag_number

Oct 27th, 2019
491
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.77 KB | None | 0 0
  1. def find_positive_magic_integer(file):
  2.     start_chars = [
  3.         *map(chr, range(ord('a'), ord('z') + 1)),
  4.         *map(chr, range(ord('A'), ord('Z') + 1)),
  5.         '_'
  6.     ]
  7.  
  8.     res = {}
  9.  
  10.     with open(file, 'r') as infile:
  11.         for i, line in enumerate(infile.read().splitlines(), 1):
  12.             elems = line.split()
  13.             if not (len(elems) == 3 and elems[0][0] in start_chars
  14.                     and elems[-1].isdigit() and line == ' '.join(elems)):
  15.                 for elem in elems:
  16.                     if elem.isdigit() and int(elem) > 1 and i not in res.get(elem, []):
  17.                         res.setdefault(elem, []).append(i)
  18.  
  19.     return res
  20.  
  21.  
  22. def fucking_find_positive_magic_integer(file):
  23.     res = {}
  24.     list(filter(lambda y:
  25.                 list(filter(lambda t: t.isdigit() and int(t) > 1
  26.                             and y[0] not in res.get(t, [])
  27.                             and res.setdefault(t, []).append(y[0]),
  28.                             y[1].split())),
  29.                 filter(lambda x:
  30.                        not (len(x[1].split()) == 3 and x[1].split()[0][0] in [
  31.                            *map(chr, range(ord('a'), ord('z') + 1)),
  32.                            *map(chr, range(ord('A'), ord('Z') + 1)),
  33.                            '_'
  34.                        ] and x[1].split()[-1].isdigit()
  35.                            and x[1] == ' '.join(x[1].split())),
  36.                        enumerate(open(file, 'r').read().splitlines(), 1))
  37.                 ))
  38.  
  39.     return res
  40.  
  41.  
  42. if __name__ == '__main__':
  43.     print(find_positive_magic_integer("./magic_number_test1.py"))
  44.     print(fucking_find_positive_magic_integer("./magic_number_test1.py"))
  45.     print(find_positive_magic_integer("./magic_number_test2.py"))
  46.     print(fucking_find_positive_magic_integer("./magic_number_test2.py"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement