Is there a TailMap implementation in Python like in Java?

Viewed 27
1 Answers

As far as I can see, there doesn't exist a built-in library, however there are a few built-in utility functions that can help us to make an quick implementation of it. Here's my quick go at it:

# tailMap.py
x = {'b': 1, 'c': 2, 'e': 3, 'a': 4, 'd': 5}

def tail_map(m, key):
    keys = sorted(m)
    keys = keys[keys.index(key):]
    return {k: m[k] for k in keys}

print(f'{tail_map(x,"c")=}')

This gave me:

> python tailMap.py
> tail_map(x,"c")={'c': 2, 'd': 5, 'e': 3}

Edit: A similar function should be adaptable to the library you referenced.

Related