I am working on a problem wherein I paste a set of numbers, and I want to put the even and odd list elements from these numbers and put them in their own list, then add them together for a 3rd list.
Here is my code:
#list of numbers
start = """
601393 168477
949122 272353
944397 564134
406351 745395
281988 610822
451328 644000
198510 606886
797923 388924
470601 938098
578263 113262
796982 62212
504090 378833
"""
x = start.split()
#turn string into list elements then append to a list
step_two = []
step_two.append(x)
print step_two
# doublecheck that step_two is a list with all the numbers
step_three = step_two[1::2]
#form new list that consists of all the odd elements
print step_three
#form new list that consists of all the even elements
step_four = step_two[0::2]
print step_four
#add ascending even/odd element pairs together and append to new list
final_step = [x + y for x, y in zip(step_three, step_four)]
print final_step
This code yields these results:
""" "Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved.
[['601393', '168477', '949122', '272353', '944397', '564134', '406351', '745395' , '281988', '610822', '451328', '644000', '198510', '606886', '797923', '388924' , '470601', '938098', '578263', '113262', '796982', '62212', '504090', '378833'] ]
[]
[['601393', '168477', '949122', '272353', '944397', '564134', '406351', '745395' , '281988', '610822', '451328', '644000', '198510', '606886', '797923', '388924' , '470601', '938098', '578263', '113262', '796982', '62212', '504090', '378833'] ]
[]
"""
Why is my list in step_three and step_four not working? I am not sure why my [::] functions aren't registering.
Thanks in advance for any advice.