Advertisement
Guest User

Consecutive Combinations

a guest
Jun 9th, 2015
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.46 KB | None | 0 0
  1. def consec_combos(ls):
  2.     combos = []
  3.     for i in xrange(len(ls)):
  4.         for j in xrange(i, len(ls)):
  5.             combos.append(ls[i:j+1])
  6.     return combos
  7.  
  8. print consec_combos('12,25,28,32,36'.split(','))
  9.  
  10. OUTPUT: [['12'], ['12', '25'], ['12', '25', '28'], ['12', '25', '28', '32'], ['12', '25', '28', '32', '36'], ['25'], ['25', '28'], ['25', '28', '32'], ['25', '28', '32', '36'], ['28'], ['28', '32'], ['28', '32', '36'], ['32'], ['32', '36'], ['36']]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement