python recurse for *args


/ Published in: Python
Save to your folder(s)

in case that you want to pass between multiple methods the same *args and unpack it
at the end


Copy this code and paste it in your HTML
  1. class Recurse:
  2.  
  3. last_t = []
  4.  
  5. def recurse(self,t):
  6. if not isinstance(t, tuple):
  7. self.last_t.append(t)
  8. else:
  9. for t1 in t:
  10. self.recurse(t1)
  11. return tuple(self.last_t)
  12.  
  13.  
  14.  
  15. d = ((((1,2,3,'test'),),),)
  16.  
  17. print Recurse().recurse(d)

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.