Created
May 5, 2013 21:54
-
-
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.
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
# 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