Created
September 5, 2018 13:45
-
-
Save kedar2a/cf3fcb7f257b640240c178204e0bbeba to your computer and use it in GitHub Desktop.
Tiny Python Snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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