, , , :
def pluralize(s, count):
if count > 1 or count == 0 or count < -1:
return s + "s"
else:
return s
Then the key understanding is to understand that you have two lists of the same size: the first is a data set, the second is a set of labels for the data. This is an ideal precedent for the combinator zip()! This combinator takes two lists (for example: [1,2,3], [4,5,6]) and combines them into one list of pairs (for example: [1,4], [2,5], [3, 6 ].)
xs = [1, 12, 1, 46]
ys = ["day", "hour", "minute", "second"]
zs = map(lambda x: [x[0], pluralize(x[1], x[0])], zip(xs,ys))
Then in zsyou get:
> print(list(zs))
> [[1, 'day'], [12, 'hours'], [1, 'minute'], [46, 'seconds']]
What you can use to create a user-submitted string.
source
share