Advertisement
Peaser

operate

Aug 9th, 2015
465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. def oper(l, method="xor"):
  2.     ops = {
  3.       "xor" : "^",
  4.       "or"  : "|", ## All maxed warning ##
  5.       "and" : "&", ## All 0 warning ##
  6.       "ls"  : "<<", ## Memory warning ##
  7.       "rs"  : ">>",
  8.       "mul" : "*",
  9.       "sub" : "-",
  10.       "add" : "+",
  11.       "div" : "/",
  12.       "mod" : "%", ## By 0 warning ##
  13.       "exp" : "**" ## Time warning ##
  14.     }
  15.     a = l[:]
  16.     for k1, v1 in enumerate(a):
  17.         for k2, v2 in enumerate(a):
  18.             exec("a[k1] {}= a[k2]".format(ops[method]))
  19.     return a
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement