How can I use variables to format my variables?
cart = {\"pinapple\": 1, \"towel\": 4, \"lube\": 1}
column_width = max(len(item) for item in items)
for item, qty
Since python 3.6 you can use f-strings resulting in more terse implementation:
>>> things = {"car": 4, "airplane": 1, "house": 2}
>>> width = max(len(thing) for thing in things)
>>> for thing, quantity in things.items():
... print(f"{thing:{width}} : {quantity}")
...
car : 4
airplane : 1
house : 2
>>>