>>> def heyfunc():
... print('hey')
...
>>> def supfunc():
... print('sup')
...
>>> funcdict = {'heyfunc': heyfunc, 'supfunc': supfunc}
>>> f_name = input()
hey
>>> next_func = funcdict.get(f_name+'func')
>>> next_func
<..function heyfunc at 0x10926d268..>
>>> next_func()
hey
card_funcs = {}
def register_cf(card_func):
'''register card function'''
card_funcs[card_func.__name__] = card_func
return card_func
@register_cf
def card_func1():
print('Running card1')
@register_cf
def card_func2():
print('Running card2')
@register_cf
def card_func3():
print('Running card3')
if __name__ == '__main__':
print('running funcs from registry:')
for fn, fobj in card_funcs.items():
print(fn, '->', fobj)
fobj()
-----
running funcs from registry:
card_func3 -> <..function card_func3 at 0x1069ae9d8..>
Running card3
card_func2 -> <..function card_func2 at 0x1071ea9d8..>
Running card2
card_func1 -> <..function card_func1 at 0x10db190d0..>
Running card1
#каждое условие отдельно
isGreaterThanFive = lambda x: x >5
isSmallerThanTen = lambda x: x<10
# или в виде комбинированого условия
matches_criteria_1 = lambda v: v >5 and v<10
n = 4
if (isGreaterThanFive(n) and isSmallerThanTen(n)):
print "matches"
else:
print "dont match"
v = 9
if (matches_criteria_1(v)):
print "matches"
else:
print "dont match"
def check_if(value):
list_if = [
('ETH+PASL', 7),
('ETH+DCR', 8),
('/pools', None),
# и так далее
]
for check_v, check_len in list_if:
if value in check_v and ((check_len == len(value)) if check_len else True):
return True
check_if(m.text)
def is_conditions_for_some_shit_pass(m):
return ((m.text in '/Ethash' and len(m.text)>7)
or (m.text in '/DCR' and len(m.text)>3)
or (m.text in '/SIA' and len(m.text)>3)
# ....
or (m.text in 'ETH+PASL' and len(m.text)==8)
or (m.text in 'ETH+DCR' and len(m.text)==7))
#####
if is_conditions_for_some_shit_pass(m):
pass
>>> d = {'coins': {'Feathercoin': {'tag': 'FTC', 'algorithm': 'NeoScrypt', 'block_time': '62.0'}}}
>>> for i in d['coins']:
print('Coins - ', i, ': ', 'Tag - ', d['coins'][i]['tag'], ': ', 'Algorithm - ', d['coins'][i]['algorithm'])
Coins - Feathercoin : Tag - FTC : Algorithm - NeoScrypt
>>> import json
>>> a = json.loads('ваша строка')
>>> res = filter(lambda x: x['algo']==20, a['result']['stats'])
>>> res
[{u'profitability_above_eth': u'16.42', u'price': u'0.0353', u'speed': u'250.11615500', u'algo': 20, u'profitability_eth': u'0.0303'}]
>>> res[0]['algo']
20
>>> res[0]['speed']
u'250.11615500'
>>> res[0]['price']
u'0.0353'