Reputation: 7331
what would be the fastest way to put the first 4 bytes of an 8 byte array in one array and the last 4 bytes in another one.
My approach was to create a for loop and then extract everything. Like this
for i in range(0,7):
if i < 4:
...
else
...
There has to be something more efficient. What am I missing?
Upvotes: 0
Views: 605
Reputation: 585
List slicing is your friend here ;)
array = [0,1,2,3,4,5,6,7] firstpart,secondpart = (array[:4],array[4:]) print firstpart [0, 1, 2, 3] print secondpart [4, 5, 6, 7]
Upvotes: 0