Bland Name Products [duplicate]

Bland Name Products [duplicate]



This question already has an answer here:



A generic trademark is what you get when a brand becomes so famous that people mistake it for the generic product.



One of the most famous examples is Velcro. The generic name is actually "hook and loop fastener". Much less catchy.



Write a program that can get rid of the brand names and replace them with the generic names.



The table below shows some brand names that have generic names. The mapping has also been provided to you in your program as the BRANDS dictionary.


BRANDS =
'Velcro': 'hook and loop fastener',
'Kleenex': 'tissues',
'Hoover': 'vacuum',
'Bandaid': 'sticking plaster',
'Thermos': 'vacuum flask',
'Dumpster': 'garbage bin',
'Rollerblade': 'inline skate',
'Asprin': 'acetylsalicylic acid'



For this problem, you need to read in a sentence, and replace all brand names with the generic names like this:



Sentence: I bought some Velcro shoes.
I bought some hook and loop fastener shoes.



Sentence: Time to Hoover the house.
Time to vacuum the house.



It should remove all brands.



Sentence: Buy some Aspirin and Kleenex.
Buy some acetylsalicylic acid and tissues.



I have tried this as my solution:


BRANDS =
'Velcro': 'hook and loop fastener',
'Kleenex': 'tissues',
'Hoover': 'vacuum',
'Bandaid': 'sticking plaster',
'Thermos': 'vacuum flask',
'Dumpster': 'garbage bin',
'Rollerblade': 'inline skate',
'Asprin': 'acetylsalicylic acid'


sentence = input('Sentence: ')

for brand in BRANDS:
sentence.replace(brand, BRANDS[brand])
print(sentence)





This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





Please, format your codes to make your questions easier to read.
– Felipe Augusto
Sep 2 at 3:15





sentence = sentence.replace(brand, BRANDS[brand]) ... replace returns a new string
– Joran Beasley
Sep 2 at 3:29


sentence = sentence.replace(brand, BRANDS[brand])





Welcome to stackoverflow, @NLynn. I trust you found the answer to your problem in the linked "duplicate" question. For the future, know that it makes a better impression if you make the effort to identify the programming task in your homework assignment (in this case: How to make multiple sequential string substitutions), and formulate your question around that. Brand names have nothing to do with the programming question here, but searching for "python multiple string substitutions" would have brought you to the solution and saved you the trouble of writing this question.
– alexis
Sep 2 at 15:45





1 Answer
1



Try this:


BRANDS =
'Velcro': 'hook and loop fastener',
'Kleenex': 'tissues',
'Hoover': 'vacuum',
'Bandaid': 'sticking plaster',
'Thermos': 'vacuum flask',
'Dumpster': 'garbage bin',
'Rollerblade': 'inline skate',
'Aspirin': 'acetylsalicylic acid'


sentence = input("Sentence: ")
for brand in BRANDS:
sentence = sentence.replace(brand, BRANDS[brand])
print(sentence)

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

How do I collapse sections of code in Visual Studio Code for Windows?

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ