I want to fill in a line with a specific format. When I have one value, it's easy to build it:
>>> x = "there are {} {} on the table.".format('3', 'books')
>>> x
'there are 3 books on the table.'
but what if i have a long list of objects
items =[{'num':3, 'obj':'books'}, {'num':1, 'obj':'pen'},...]
and I want to build the sentence in exactly the same way:
There are 3 books and 1 pen and 2 cellphones and... on the table
How can I do this, given that I do not know the length of the list? Using format, I could easily build a string, but then I have to know the length of the list in advance.
source
share