Created
July 10, 2019 07:30
-
-
Save lokesh1729/b786a2b88c06d9369e2ae84f693facd3 to your computer and use it in GitHub Desktop.
divide an array into contiguous k sub arrays
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 divide(data, n_column=3): | |
result = [] | |
cur_index = 0 | |
n = len(data) | |
while cur_index < n/n_column: | |
result.append(data[cur_index*n_column: (cur_index+1)*n_column]) | |
cur_index += 1 | |
if n%n_column != 0: | |
result.append(data[cur_index*n_column: (cur_index+1)*n_column]) | |
return result |
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 divide(data, n_column=3): | |
result = [] | |
cur_index = 0 | |
n = len(data) | |
while cur_index <= n//n_column: | |
arr = data[cur_index*n_column: (cur_index+1)*n_column] | |
if arr: | |
result.append(arr) | |
cur_index += 1 | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment