For example, I want to print only keys that contain 'a' characters in the dictionary named 'dics = { 'abdc' : 1234, 'abbbd' : 1244, 'adffbg' : 1255, 'bbbffgrg' = 1666}. How do I print them?
python dictionary
>>> d = { 'abdc' : 1234, 'abbbd' : 1244, 'adffbg' : 1255, 'bbffgrg' : 1666}
>>> d.keys()
dict_keys(['abdc', 'abbbd', 'adffbg', 'bbffgrg'])
>>> [ k for k in d.keys() if 'a' in k ]
['abdc', 'abbbd', 'adffbg']
© 2024 OneMinuteCode. All rights reserved.