importredefhydrate(drinks:str)->str:drinkCount=sum(map(int,re.findall("\d+",drinks)))# total number of drinks
# this will also work, drinkCount = sum([int(num) for num in drinks.split(" ") if num.isdigit()])
returnstr(drinkCount)+" glass"+("es"ifdrinkCount>1else"")+" of water"print(hydrate("1 beer"))# output -> 1 glass of water
print(hydrate("2 glasses of wine and 1 shot"))# output -> 3 glasses of water
print(hydrate("1 shot, 5 beers, 2 shots, 1 glass of wine, 1 beer"))# output -> 10 glasses of water
Hey Vidit, I'm happy to hear you wanna suggest a challenge. You can send any suggestions to yo+challenge@dev.to. Feel free to drop the content of your challenge in the email, markdown file works too. Subject doesn't matter too much, we'll know what it is.
Python solution
I want to suggest a challenge. What should be the subject of my email? Can I send a markdown file?
Hey Vidit, I'm happy to hear you wanna suggest a challenge. You can send any suggestions to yo+challenge@dev.to. Feel free to drop the content of your challenge in the email, markdown file works too. Subject doesn't matter too much, we'll know what it is.
Take care!
Thanks!