Created
May 11, 2019 17:22
-
-
Save mIcHyAmRaNe/1f7f5cf64368cbc17627f1902af492b7 to your computer and use it in GitHub Desktop.
divide list python
This file contains 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
num = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'] | |
list(zip(num[0::3], num[1::3], num[2::3])) | |
#output: [('1', '2', '3'), ('4', '5', '6'), ('7', '8', '9'), ('10', '11', '12')] | |
parts = [] | |
for start_index in range(0, len(num), len(num) // 4): | |
end_index = start_index + len(num)//4 | |
parts.append(num[start_index:end_index]) | |
print(parts[0]) | |
print(parts[1]) | |
print(parts[2]) | |
print(parts[3]) | |
# output: | |
# ['1', '2', '3'] | |
# ['4', '5', '6'] | |
# ['7', '8', '9'] | |
# ['10', '11', '12'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment