不打印"发现";,我想打印相关的数值
def lookupHostGroup(group):
hostgroups = [
['Maas GCP Pod M005', '134'],
['Maas GCP Pod M006', '136'],
['Maas GCP Pod M007', '135'],
['Maas GCP Pod M009', '156'],
['Maas GCP Pod M001', '168'],
['Maas GCP Pod M0011', '166']
]
for hg in hostgroups:
if hg[0] == group:
print ("found")
return hg[0]
print(lookupHostGroup("Maas GCP Pod M007"))
让Python为您完成工作。
hostgroups = {
'Maas GCP Pod M005': '134',
'Maas GCP Pod M006': '136',
'Maas GCP Pod M007': '135',
'Maas GCP Pod M009': '156',
'Maas GCP Pod M001': '168',
'Maas GCP Pod M0011': '166'
}
def lookupHostGroup(group):
return hostgroups[group]
print(lookupHostGroup("Maas GCP Pod M007"))
def lookupHostGroup(group):
hostgroups = [
['Maas GCP Pod M005', '134'],
['Maas GCP Pod M006', '136'],
['Maas GCP Pod M007', '135'],
['Maas GCP Pod M009', '156'],
['Maas GCP Pod M001', '168'],
['Maas GCP Pod M0011', '166']
]
for hg in hostgroups:
if hg[0] == group:
return int(hg[1])
print(lookupHostGroup("Maas GCP Pod M007"))
这应该行得通