如何只打印()该词典中的第一个列表?
drugs = {
"Stimulants":["Ecstsy","Cocaine","Amphetamine"],#list only that I want to print()
"Depressants":["Marijuana","Benzodiazepine","Heroin","Morphine"],
"Hallucinogens":["LSD","Marijuana","Psilocybin"],
"Opioids":["Codeine","Heroin","Methadone","Ocycodone"],
}
因为我写的时候。
if customer_0 == "Stimulants":
print("\nFrom Stimulants we have:")
for drugs_0 in drugs.values():
print("\t" + str(drugs_0[0]))
它支持我
"Ecstsy",
"Marijuana",
"LSD",
"Codeine"
但是我要它打印出来。
"Ecstsy",
"Cocaine",
"Amphetamine",
答案 0 :(得分:0)
这将起作用:
items = drugs.get("Stimulants")
for item in items:
print(item)
输出:
Ecstsy
Cocaine
Amphetamine