python - How would you abstract this series of list continue conditions? -


i have source code has number of conditions lead skipping rest of current list iteration:

for name, row in recent.iteritems():     if name in ignore:         print name + "is on ignore list. skipping."         continue      if number_of_open_orders_in(name) == max_orders_per_market:         print name + "has max number of open orders. skipping."         continue      if row[0].ask < 100e-8:         print name + "is single or double satoshi coin. skipping."         continue      gain.append(         (             name,             percent_gain(row[0].ask, row[1].ask),             row[1].ask,             row[0].ask,             'https://bittrex.com/market/index?marketname={0}'.format(name),         )     ) 

as can see, code regular. each reason skipping

  1. performs test function of row or name
  2. if test returns true,
    • print message
    • skip current loop iteration

the following code redundancy removed:

for name, row in recent.iteritems():     if name in ignore:         print name + "is on ignore list. skipping."      elif number_of_open_orders_in(name) == max_orders_per_market:         print name + "has max number of open orders. skipping."      elif row[0].ask < 100e-8:         print name + "is single or double satoshi coin. skipping."      else:         gain.append(             (                 name,                 percent_gain(row[0].ask, row[1].ask),                 row[1].ask,                 row[0].ask,                 'https://bittrex.com/market/index?marketname={0}'.format(name),             )         ) 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -