Python 3.4 - Unpack List or Tuples

 There are multiple ways to separate items in a list or tuple:

list = ['Yesterday', 'Beer', 8.51]

date, item, price = ['Yesterday', 'Beer', 8.51]

print(list)

print(item)

You can access a list and the items within it using functions and then have the function do something with those items.

def drop_first_last(grades):
    first, *middle, last = grades
    avg = sum(middle) / len(middle)
    print(avg)

drop_first_last([65, 75, 65, 88, 99, 34, 22, 10, 99])


https://www.youtube.com/watch?v=XhXOsgdC9h0

Comments

Popular posts from this blog

Pyhton 3.4 - Continue

Conversations Ongoing: Valuing Modernization in Early European History

Conversations Ongoing: A Bunch of Amateurs