0

How can I make a function to return the lowest number in a list like:

listA = [[10,20,30],[40,50,60],[70,80,90]]

I want it to return 10

jamylak
  • 128,818
  • 30
  • 231
  • 230
M T
  • 5
  • 3
  • 1
    possible duplicate of [Flattening a shallow list in Python](http://stackoverflow.com/questions/406121/flattening-a-shallow-list-in-python) – whereswalden Apr 12 '15 at 03:04

4 Answers4

2

Flatten the list by using itertools.chain, then find the minimum as you would otherwise:

from itertools import chain

listA = [[10,20,30],[40,50,60],[70,80,90]]
min(chain.from_iterable(listA))
# 10
nelfin
  • 1,019
  • 7
  • 14
1
>>> listA = [[10,20,30],[40,50,60],[70,80,90]]
>>> min(y for x in listA for y in x)
10
jamylak
  • 128,818
  • 30
  • 231
  • 230
0

Set result to float("inf"). Iterate over every number in every list and call each number i. If i is less than result, result = i. Once you're done, result will contain the lowest value.

Schilcote
  • 2,344
  • 1
  • 17
  • 35
0

This is possible using list comprehension

>>> listA = [[10,20,30],[40,50,60],[70,80,90]]
>>> output = [y for x in listA for y in x]
>>> min(output)
10