Collections
Lists are ordered sequences. Dicts map keys to values. Both are delightfully flexible and occasionally too flexible.
fruits = ["apple", "banana"]
prices = {"apple": 3}
print(fruits[::-1]) # reverse — Pythonic magicQuirk #5 — Slicing: lst[start:stop:step] is one of Python's superpowers. [::-1] reverses a list. [:] makes a shallow copy (usually).
Try it
fruits.append("durian")— the world's most opinionated fruit.- Sum all prices with a loop or
sum(prices.values()).
Output
Press Run to execute your code.