Created
June 24, 2016 16:28
-
-
Save darjanin/27e6f3c13aee147099e3ceee30b869ef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
zemiak = [ | |
('Tesco', 20, 7.99), | |
('Lidl', 10, 9.5), | |
('Kaufland', 20, 6.99), | |
('GVP', 5, 2.3) | |
] | |
def cena_za_kilogram(balenie): | |
return balenie[2] / balenie[1] | |
utriedene_zemiaky = sorted(zemiak, key=cena_za_kilogram) | |
for znacka, hmotnost, cena in utriedene_zemiaky: | |
print("{}, {}kg, {}e".format(znacka, hmotnost, cena)) | |
# nasledujuci kod iba ukazka ze to ide aj kratsie 8D, ale ten prvy kod pokladam za najcitatelnejsiu verziu. | |
# zaroven som nijako nezmenil povodne data, takze ak chcem s nimi nieco ine spravit tak ich mam stale dostupne. | |
# for znacka, hmotnost, cena in sorted(zemiak, key=lambda balenie: balenie[2] / balenie[1]): | |
# print("{}, {}kg, {}e".format(znacka, hmotnost, cena)) | |
# def porovnaj(zemiak): #maturitna bandurky | |
# return zemiak[3] | |
# | |
# zemiak=[['Tesco',20,7.99], ['Lidl',10,9.5], ['Kaufland',20,6.99], ['GVP',5,2.3]] | |
# | |
# for i in range (len(zemiak)): | |
# zemiak[i].append(zemiak[i][2]/zemiak[i][1]) | |
# | |
# print (zemiak) | |
# zemiak.sort(key=porovnaj) # usporiada podla 3 prvku zemiaka | |
# print ("Usporiadane: ", zemiak) | |
# for firma, kg,cena,p in zemiak: | |
# print (firma,kg,cena,p) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment