14. The following vehicles and home plate, forming a new dictionary, shows how much each of the home vehicle Total:

Plates and the following vehicle home, forming a new dictionary, shows how much each of the home vehicle Total:
cars = [ 'Lu A32444', 'Lu B12333', 'Beijing B8989M', 'Black & C49678', 'black and C46555 '' Shanghai B25044 ',' Ji G11111 ',' Black & C42355 ']
about locals = {' Ji ':' Hebei ',' Black & ':' Black & ⻰ river ',' Lu ':' ⼭ East ',' E ' : 'Hubei', 'Gordon': 'Hunan', 'Beijing': 'Beijing'}
result: { 'black and ⻰ River': 3, '⼭ East': 2, 'Beijing': 1, 'Hebei': 1 }
The first:
DIC = {}
Li = []
for I in cars:
IF I [0] in about locals:
li.append (I)
for J in Li:
DIC [about locals [J [0]]] = DIC. GET (about locals [J [0]], 0) + 1'd
Print (DIC)
second:
DIC = {}
for I in cars:
IF locals.get (I [0]):
DIC [about locals [I [0] ]] = dic.get (locals [i [0]],0) + 1
print (say)

Guess you like

Origin www.cnblogs.com/pythonblogs/p/11025326.html