For instance, if I have a list of words:
Words = ['A', 'list', 'of', 'words']
and want a second list to reference the lengths of those words, how could I achieve this? I’m aware that I could do something like:
Lengths = map(lambda w: len(w), Words)
[1, 4, 2, 5]
but I would have to continually call that function every time Words is altered.
You could use a class:
It’s the first time I use a class, so there might be a better way. However this seems to work well. You would need to define other methods for other operations such as insert, remove, etc.