Skip to content

Instantly share code, notes, and snippets.

@kedar2a
Created September 5, 2018 13:45
Show Gist options
  • Save kedar2a/cf3fcb7f257b640240c178204e0bbeba to your computer and use it in GitHub Desktop.
Save kedar2a/cf3fcb7f257b640240c178204e0bbeba to your computer and use it in GitHub Desktop.
Tiny Python Snippets
def rec_split(arr=[], start=0, end=0):
'''
Recursively split list by 2 till end of all sublists to
have leaf list of length 1.
Example:
>>> sl = [2,3,4, 99, 76,12, 5]
>>> rec_split(sl)
[2, 3, 4]
[99, 76, 12, 5]
[2]
[3, 4]
[3]
[4]
[99, 76]
[12, 5]
[99]
[76]
[12]
[5]
'''
ln = len(arr)
if ln > 1:
m = ln/2
l1 = arr[:m]
print l1
l2 = arr[m:]
print l2
split(l1), split(l2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment