Python小程序(3)之字典的使用
Python中字典感觉和C++中的map差不多嘛。当单位插入到字典中时,顺序可能会改变,应是根据键的字典序来排列的。
字典就那么几个函数,如:
d.pop(); d.items(); d.values(); d.keys(); d.copy();d.clear(); d.update(e); (e是键-值类型)
个人认为d.items(); d.get(key); d.update(e); d.pop(); d.copy();d.clear()比较重要,记住几个常用的就行了。
import re def main(): color = {'red':1, 'blue':2, 'gress':3, 'orange':4} map = color.copy() print('color:', color) print('map:', map) lst = [] k = color.values() for i in k: print('values:', i, end = ' ') if i >= 1: lst.append(i) print('\nlst:', lst) print('\n') map.clear() color.clear() #################################################### map = {6:'red', 5:'blue', 4:'gress', 3:'orange', 2:'gresssss!', 1:'gressss!!'} color = map.copy() print('color:', color) print('map:', map) result = [] k = map.items() for i in k: print('items:', i, end = ' ') d = re.match('gress', i[1]) if d: result.append(i[1]) print('\nresult:', result) map.clear() color.clear()
2022年8月24日 13:25
Maharashtra HSC Model Question Papers 2023 Download, The state board of Mah state which is Maharashtra State Board of Secondary & Higher Secondary Education situated in Pune. Maharashtra, Maha 12th Class Important Question Paper 2023 a state spanning west-central India is best known for its fast-paced capital, Mumbai formerly Bombay as per the Wiki. Higher Secondary Certificate which is referred as HSC is the certificate issued to the candidates qualified the 10+2 examinations.
2023年1月03日 19:45
Python applets often use dictionaries to store data. Dictionaries are a type of data structure that allows buy cheap diamond rings for efficient storage and retrieval of data. Dictionaries are used in Python applets because they are easy to use and provide a quick way to access data.