Skip to content

Instantly share code, notes, and snippets.

@Caleb2501
Created May 5, 2013 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Caleb2501/5522338 to your computer and use it in GitHub Desktop.
Save Caleb2501/5522338 to your computer and use it in GitHub Desktop.
In this challenge I sent one value to the function and returned two using the multi-assign ability in Python I was able to assign them to new variables. That was pretty sweet.
# Input: a list
# Output: Return the two halves as different lists.
# If the input list has an odd number, the middle item can go to any of the list.
# Your task is to write the function that splits a list in two halves.
fullList = ['1', '2', '3', '4', 'alpha', 'beta', 'triangle', 'soup', 'pickle']
def listSplitter(fullList):
""" This function takes 1 list value, and returns 2 lists of the original split in half."""
listSize = len(fullList)
if listSize%2 == 0:
firstList = fullList[:listSize/2]
secondList = fullList[listSize/2:]
else:
firstList = fullList[:(listSize+1)/2]
secondList = fullList[(listSize+1)/2:]
return firstList, secondList
list1, list2 = listSplitter(fullList)
print "Here is the original list: ", fullList
print "Here are the two modified lists:"
print list1, " and ", list2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment