Quick actions

cmd+k|ctrl+k

Navigation

Languages

CS1_HW1

Snippet info

Language

Python

Visibility

public

Author

apizzimenti

Created

2016-09-09T22:25:47Z

Updated

2016-09-09T22:54:50Z


# puzzle 0
def halfSequence(s):
    length = len(s) // 2
    
    part1 = s[0:length]
    part2 = s[(length):len(s)]
    
    return (part1, part2)
    

# puzzle 1
def distribute(s):
    
    avg = sum(s) // len(s)
    leftover = sum(s) % len(s)
    return (([avg] * (len(s) - leftover) + ([avg + 1] * leftover)))
    
# puzzle 2
def inBoth(s1, s2):
    
    s1 = list(s1)
    
    return tuple([c for c in s1 if c in s2])

# puzzle 3
def inEither(s1, s2):
    
    return tuple([c for c in list(s1) if c not in s2]) + tuple([c for c in list(s2) if c not in s1])

# puzzle 4
def isContained(w):
    
    return [word for (i, word) in enumerate(w) if (len(inBoth(w[i - 1], w[i])) == len(w[i - 1]))]
    
print(isContained(["this", "at", "that", "is"]))
INFO