课程: Hands-On Advanced Python: Data Engineering Basics

免费学习该课程!

今天就开通帐号,24,700 门业界名师课程任您挑!

Solution: Random days

Solution: Random days

- [Instructor] Okay, let's take a look at my solution for this particular challenge. And for this challenge we had to select five non-duplicate random days from a given year and month and return them in a list. So here in my solution, what I do first is I concatenate the year and the month into a single string separated by a dash, because that's the date format that's used by the sample data. And that gives me an easy way of filtering out the rest of the data and only keeping the days that are in the year and month, which is what the next part of the code does. This is the year, month filter, callback function and this call to filter. So I'm filtering out all of the days that are not within the year and the month that my function is given. So once I have this piece of code executed, I now have a list of eligible days from which I can select five random days. And to do that, I'm using the random sample function to…

内容