What is the dictionary and collection in python
This article mainly introduces what is the dictionary and collection in python, which has certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let Xiaobian take you to understand it together.
Dictionary/Set Understanding
Just as we use list inference, we can also use dictionary/set inference. They are easy to use and equally effective. This is an example.
testDict = {i: i * i for i in xrange(10)} testSet = {i * 2 for i in xrange(10)}print(testSet)print(testDict)#set([0, 2, 4, 6, 8, 10, 12, 14, 16, 18])#{0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6: 36, 7: 49, 8: 64, 9: 81}
Note-the only difference between the two statements is. Also, to run the above code in Python 3, replace with.
Thank you for reading this article carefully. I hope that Xiaobian's article "What are dictionaries and collections in python" will be helpful to everyone. At the same time, I hope that everyone will support you a lot and pay attention to the industry information channel. More relevant knowledge is waiting for you to learn!