【发布时间】:2019-02-01 14:56:33
【问题描述】:
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: )
我希望它打印如下内容:
Sentence: I bought some Velcro shoes.
I bought some hook and loop fastener shoes.
【问题讨论】:
-
那个作业不是几周前就出来了吗?你在化妆吗?
-
print(' '.join(BRANDS.get(i, i) for i in sentence.split())) -
你应该以鞋品牌为输入,从dict中获取key并造句。
-
' '.join(BRANDS.get(val,val) for val in sentence.split(' '))
-
@U9-转发很酷,谢谢。
标签: python string python-3.x dictionary replace