CS1_HW1

Run Settings
LanguagePython
Language Version
Run Command
# 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"]))
Editor Settings
Theme
Key bindings
Full width
Lines