Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,8 @@
|
|||
if x == 0:
|
||||
foo()
|
||||
elif x == 1:
|
||||
bar()
|
||||
elif x == 2:
|
||||
baz()
|
||||
else:
|
||||
boz()
|
||||
|
|
@ -0,0 +1 @@
|
|||
true_value if condition else false_value
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
>>> secret='foo'
|
||||
>>> print 'got it' if secret=='foo' else 'try again'
|
||||
'got it'
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
>>> secret = 'foo'
|
||||
>>> result = 'got it' if secret=='foo' else 'try again'
|
||||
>>> print result
|
||||
'got it'
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
dispatcher = dict()
|
||||
dispatcher[0]=foo # Not foo(): we bind the dictionary entry to the function's object,
|
||||
# NOT to the results returned by an invocation of the function
|
||||
dispatcher[1]=bar
|
||||
dispatcher[2]=baz # foo,bar, baz, and boz are defined functions.
|
||||
|
||||
# Then later
|
||||
results = dispatcher.get(x, boz)() # binding results to a name is optional
|
||||
# or with no "default" case:
|
||||
if x in dispatcher:
|
||||
results=dispatcher[x]()
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
# The above, but with a dict literal
|
||||
dispatcher = {
|
||||
0: foo,
|
||||
1: bar,
|
||||
2: baz,
|
||||
}
|
||||
# ...
|
||||
results = dispatcher.get(x, boz)()
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
# Or without the temp variable
|
||||
# (it's up to the reader to decide how "pythonic" this is or isn't)
|
||||
results = {
|
||||
0: foo,
|
||||
1: bar,
|
||||
2: baz,
|
||||
}.get(x, boz)()
|
||||
Loading…
Add table
Add a link
Reference in a new issue