Skip to content

Instantly share code, notes, and snippets.

@mIcHyAmRaNe
Created May 11, 2019 17:22
Show Gist options
  • Save mIcHyAmRaNe/1f7f5cf64368cbc17627f1902af492b7 to your computer and use it in GitHub Desktop.
Save mIcHyAmRaNe/1f7f5cf64368cbc17627f1902af492b7 to your computer and use it in GitHub Desktop.
divide list python
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