今天就学习课程吧!
今天就开通帐号,24,600 门业界名师课程任您挑!
OrderedDict
- [Instructor] One of the main downsides of the regular dictionary object in Python is that it doesn't keep track of any order among the items. The OrderedDict is a dictionary object that remembers the order in which items are inserted, and we'll take a look at that in this example now. So I'm going to open up the ordereddict_start file here in my Collections folder. And here in my code, I have a list of tuples, each of which represents a sports team, along with a tuple that contains their win and loss record. And I'm using the built-in sorted function to sort the list by the number of wins. And we saw this function earlier in the course. And you can see that the key function I'm using here is a lambda function, which is getting the first item in the embedded tuple here to sort by the number of wins. And you can also see that I'm using an OrderedDict. I'm importing OrderedDict here from the collections, from the Collections module. And what I'm going to do first is I'll use this list…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。