For a lack of better words, I went with this title.
What I want is to be able to do something like this:
>>> from random import randint
>>> fruits = [
... "Orange",
... "Banana",
... f"{randint(2,5)} Cherries",
... ]
>>> fruits[2]
'3 Cherries'
>>> fruits[2]
'5 Cherries'
>>> fruits[2]
'2 Cherries'
But instead, the literal expression inside the string gets evaluated once upon the creation of the list and gives the same result each time I access it.
I was wondering whether there was an easier/smarter way to approach this other than writing some complicated edge case handling (we're programmers after all; who doesn't like writing nice code and being all elegant and fancy?). I speak of edge case handling because only 6 of my 49 strings require this kind of "special" behaviour.
What I've tried so far is making a lambda function out of the randint call, this doesn't help though; same result. Maybe this is a case for lazy evaluation, but I need a little guidance on how (or whether?) to use it with a list.