aneroid

puritanical functional code to avoid deep nesting

Feb 25th, 2021
1,102
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # for https://chat.stackoverflow.com/transcript/message/51671357#51671357
  2.  
  3. def looper():
  4.     def lst1_func():
  5.         nonlocal i1, a, b, c, d
  6.         # do stuff
  7.    
  8.     def lst2_func():
  9.         nonlocal i2, a, b, c, d
  10.         # do stuff
  11.    
  12.     # def lst3_func, lst4_func here
  13.    
  14.     triplets = [(lst1, lst1_func, lambda x: x.upper() in bar),
  15.                 (lst2, lst2_func, lambda x: x in foo),
  16.                 (lst3, lst3_func, lambda x: x),
  17.                 (lst4, lst4_func, lambda x: x not in lst1),
  18.     ]
  19.    
  20.     for lst, func, condition in triplets:
  21.         for item in lst:
  22.             if condition(item):
  23.                 return
  24.             func()
  25.    
  26.     print('Never broke')
  27.  
  28.  
  29. looper()
  30.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×