pics = ["1.jpg", "2.jpg", "3.jpg", "4.jpg", "7.jpg", "5.jpg", "9.jpg", "8.jpg", "10.jpg", "11.jpg"]
pics.sort()
pics
list(reversed(pics))
pics
sortedpics = sorted(pics)
sortedpics
pics
pics.sort()
pics
pics
pics = [name.split('.')[0] for name in pics]
pics
def str_to_num(s):
return int(s)
str_to_num(pics[2])
'11' < '2'
11 > 2
sorted(pics, key=str_to_num)
int('11')
sorted(pics, key=int)
pics
bank_customers = [
{ "name": "aviad", "tel": "053", "id" : "0358"},
{ "name": "moshe", "tel": "054", "id" : "0123"},
{ "name": "david", "tel": "055", "id" : "456"}
]
def name_from_customer(customer):
"""
{ "name": "aviad", "tel": "053", "id" : "0358"},
"""
return customer["name"]
sorted(bank_customers, key=name_from_customer)
def id_from_customer(customer):
"""
{ "name": "aviad", "tel": "053", "id" : "0358"},
"""
return customer["id"]
sorted(bank_customers, key=id_from_customer)
pics
sorted(pics, key=int, reverse=True)
"the quick brown fox jumped over the lazy dog".split()[1:].index("the")
"helo".find("e")
"the quick brown fox jumped over the lazy dog".split().