Last active
October 16, 2016 07:37
-
-
Save Kalaborative/bb131b7289903fcef0762da7413c5cb0 to your computer and use it in GitHub Desktop.
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
import sys | |
print "Type a list of numbers with 3 in the middle." | |
myl = input('> ') | |
n = [] | |
# Find the index of 3. | |
idx = myl.index(3) | |
try: | |
n.append(myl.pop(idx)) # Removes '3' from the list and stores it in n | |
except AttributeError: | |
print "Your list did not include brackets" | |
sys.exit() | |
# Split the list at the index | |
foo = [myl[x:x + idx] for x in xrange(0, len(myl), idx)] | |
# Reverse the list of lists | |
foo.reverse() | |
# After the first list (at index 0), insert [3] | |
foo.insert(1, n) | |
# Flatten the list | |
bar = [item for sublist in foo for item in sublist] | |
# print the list | |
print bar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: does not work as expected when '3' is at index 1