Splitting lists?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • woodwardo
    New Member
    • Apr 2010
    • 1

    Splitting lists?

    I have this list:

    Code:
       people = [ ("JT", 150), ("TJ", 80), ("TT", 120), ("BT", 170), ("Mike", 12), \
                  ("AF", 27), ("Lea", 78), ("Leo", 180), ("Al", 55), ("GK", 110),  \
                  ("JR", 111), ("VB", 76) ]
    I'm trying to add the five lowest integers (12, 27, 55, 76, 78) together, but I don't know how to divide the integers from the strings...can I split them?
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Code:
    >>> numbers = [item[1] for item in people]
    >>> numbers.sort()
    >>> sum(numbers[:5])
    248
    >>>

    Comment

    Working...