Skip to content

Instantly share code, notes, and snippets.

@lll9p
Last active August 12, 2016 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lll9p/148d4b04417edc0c0df2a9eea8ce5cd9 to your computer and use it in GitHub Desktop.
Save lll9p/148d4b04417edc0c0df2a9eea8ce5cd9 to your computer and use it in GitHub Desktop.
# https://www.v2ex.com/t/298833
from xx import my_get_s
ss = [int(my_get_s()) for i in range(3)]
# dict version
conds = ({1: 1, 2: 2, 3: 5, 4: 9, 5: 7, 6: 8, }, # x
{1: 1, 2: 6, 3: 6, 4: 8, }, # y
{1: 8, 2: 5, 3: 2, 4: 7, 5: 3, }, # z
)
x, y, z = map(lambda d, s: d.get(s, -1), conds, ss)
# tuple version
conds = ((1, 2, 5, 9, 7, 8), # x
(1, 6, 6, 8), # y
(8, 5, 2, 7, 3), # z
)
x, y, z = map(lambda l, s: l[s - 1] if 0 <= s < len(l) else -1, conds, ss)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment