Esempio n. 1
0
def rlePropRoundTrip(lst: List) -> bool:
    # iS: ord('a') returns Unicode (97), count starts an iterator at 97, map maps each
    # yielded element of the iterator to chr. islice takes a len(lst) slice from
    # the iterator, zips it with the lambda function mapping on the list, and
    # returns the list of that zip.
    iS: List = list(
        zip(islice(compose(map(chr), count, ord)('a'), len(lst)),
            map(lambda x: (x % 100) + 1, lst)))
    # xs: the list comprehension repeats the charater, the second element of the tuple
    # times, for each tuple in iS. The resulting list is then made into a string
    xs: str = "".join([first(x) * second(x) for x in iS])
    return runLengthEncode(xs) == iS
Esempio n. 2
0
def runLengthEncode(lst: Union[List, str]) -> List[Tuple[Any, int]]:
    n: int = 1
    newList: List = []
    while len(lst) > 0:
        if len(lst) == 1:
            newList.append((first(lst), n))
            return newList
        elif first(lst) == second(lst):
            n += 1
            lst = list(drop(1, lst))
        else:
            newList.append((first(lst), n))
            lst = list(drop(1, lst))
            n = 1
    return newList
Esempio n. 3
0
def showWithName(person) -> Optional[str]:
    shows = list(
        filter(lambda s: person.name in s,
               list(map(lambda s: second(s), tvShows))))
    return first(shows) if shows else None
Esempio n. 4
0
def showForYear(person) -> Optional[str]:
    for show in tvShows:
        if first(show) == person.year:
            return second(show)
    else:
        pass
Esempio n. 5
0
def test_second():
    for p in pairs:
        second(p)
Esempio n. 6
0
def test_second_iter():
    iters = map(iter, [(1, 2) for i in range(1000000)])
    for p in iters:
        second(p)
def value_includes(value, kv_pair):
    return value in second(kv_pair)