Advertisement
here2share

# bifurcate_by.py

Jul 20th, 2022
872
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.27 KB | None | 0 0
  1. # bifurcate_by.py
  2.  
  3. def bifurcate_by(lst, fn):
  4.     t = [[],[]]
  5.     for x in lst:
  6.         if x[0] == 'b':
  7.             t[0] += [x]
  8.         else:
  9.             t[1] += [x]
  10.     return t
  11.  
  12. t = bifurcate_by(['beep', 'boop', 'foo', 'bar'], lambda x: x[0] == 'b')
  13. print(t)
  14. # [ ['beep', 'boop', 'bar'], ['foo'] ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement