From the course: Advanced Python
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Solution: Using Iterators - Python Tutorial
From the course: Advanced Python
Solution: Using Iterators
- [Instructor] Alright, so to find the largest number in multiple lists of numbers, we need to do two things. First, we need to be able to search all of the lists. There are a few different ways you could solve this problem, but for my solution, I chose to use the chain.from_Iterable function, which is in the ITER tools module. That function will take the list of lists that we are given and iterate over all of the values, iterating over each list, after it exhausts the previous list, then all you need to do is wrap that function call with a call to the built-in max function, which will find the largest number. So let's go ahead and run that, and you can see that my code has found the largest number, which is 92, which is somewhere in here. I'm not sure exactly where it other is. It's right there. Let's try changing another number to make it the largest number. So let's make this 125 and then let's run the code again. And now you can see that we're returning 125 as the largest number…
Contents
-
-
-
-
(Locked)
Basic iterators4m 20s
-
(Locked)
More iterators7m 4s
-
(Locked)
For-else3m 37s
-
Itertools: count, cycle, accumulate6m 46s
-
(Locked)
Itertools: chain, chain.from_iterable, batched3m 25s
-
(Locked)
Itertools: dropwhile, takewhile, filterfalse6m 2s
-
(Locked)
Itertools: combinations and permutations6m 5s
-
(Locked)
Solution: Using Iterators1m 10s
-
(Locked)
-
-
-
-