I need to take a series of text inputs, and combine them with a number and some formatting. The catch is that I don't know how many elements the series of inputs will have beforehand. I know this would be easy to do for a set number of inputs, but I need a function that will iterate as many as necessary.
So basically I need to take 'apple banana cherry ...' and '5' and output:
str('{"apple": 5, "banana": 5, "cherry": 5, "...": 5}')
This is what I have so far:
print("Enter fruits:")
fruits = [x for x in input().split()]
print("Enter Maximum Fruits per Day")
maxfruit = input()
def maxfruitfuncstep1(x,y):
return str('"' + x + '"' + ": " + y)
for i in fruits:
print("{" + maxfruitfuncstep1(i,maxfruit) + "}")
but that just gives me output:
{"apple": 5}
{"banana": 5}
{"cherry": 5}
How can I get the function to run horizontally within the printout? I've tried using ",".join but that just gave me:
",a,p,p,l,e,",:, ,5