https://naucse.python.cz/2024/praha-pyladies-podzim/sessions/list/
Created
November 8, 2024 13:37
-
-
Save brabemi/fe80874ef1e8343a81eb5f9b3d9fc4a1 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
seznam_cisel = [1, 2, 1, 4] | |
print(seznam_cisel) | |
seznam_2 = [1, "jedna", True, None] | |
print(seznam_2) | |
for znak in "cokolada": | |
print(znak) | |
for prvek in seznam_2: | |
print(prvek) | |
mesice = [ | |
"leden", | |
"unor", | |
"brezen", | |
"duben", | |
"kveten", | |
"cerven" | |
# ... | |
] | |
print(mesice) | |
q1 = mesice[0:3] | |
q2 = mesice[3:6] | |
print("Q1 jsou", ', '.join(q1)) | |
print("Q2 jsou", q2) | |
# cisla = [1, 4, 6, 11, 8] | |
# print("+".join([1, 2]), "=", sum(cisla)) | |
cisla = [] | |
from random import randrange | |
for pokus in range(10): | |
print(cisla) | |
cislo = randrange(100) | |
cisla.append(cislo) # přidání do seznamu | |
cisla[0] = cislo # změna na daném indexu |
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
jmeno = "pepa" | |
jmeno2 = jmeno | |
print(jmeno, jmeno2) | |
jmeno = "karel" | |
print(jmeno, jmeno2) | |
l_jmeno = ["pepa"] | |
l_jmeno2 = l_jmeno | |
print(l_jmeno, l_jmeno2) | |
# l_jmeno[0] = "karel" | |
l_jmeno.append("karel") | |
print(l_jmeno, l_jmeno2) |
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
seznam_1 = ["jablko", "hruška"] | |
seznam_2 = ["citrón", "meloun"] | |
seznam_1.append("pomeranč") | |
print(seznam_1) | |
seznam_3 = seznam_1 + seznam_2 | |
# seznam_4 = [] + seznam_1 | |
muj_seznam = seznam_1 | |
print(muj_seznam is seznam_1) | |
seznam_1 = seznam_1 + seznam_2 | |
# vs | |
muj_seznam.extend(seznam_2) | |
print(muj_seznam is seznam_1) | |
print(muj_seznam) | |
print(seznam_1) | |
print(muj_seznam == seznam_1) | |
# seznam_3.append("pomelo") | |
# print(seznam_1) | |
# print(seznam_3) | |
print(muj_seznam.pop()) | |
print(muj_seznam) | |
del muj_seznam[0] | |
print(muj_seznam) | |
# napište funkci, která dostane seznam čísel | |
# parametr nove_cislo , které přidá na konec | |
# parametr smaz, počet prvků na začátku ke smazání | |
def pridej_a_smaz(seznam, nove_cislo, smaz): | |
seznam.append(nove_cislo) | |
del seznam[:smaz] | |
return seznam | |
seznam = [1, 3, 6, 7, 8, 9] | |
print(pridej_a_smaz(seznam, 13, 3)) # -> [7, 8, 9, 13] |
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
zvirata = [ | |
"pes", | |
"koza", | |
"kočka", | |
"andulka", | |
"had", | |
] | |
print("hroch" in zvirata) | |
print("pes" in zvirata) | |
zvirata_s_a = [] | |
for zvire in zvirata: | |
if 'a' in zvire.lower(): | |
zvirata_s_a.append(zvire) | |
print(zvirata_s_a) | |
print('-'*30) | |
print(zvirata) | |
print(sorted(zvirata,reverse=True)) | |
# print(zvirata.append('hroch')) | |
zvirata.sort(reverse=True) | |
print(zvirata) | |
print('-'*30) | |
a = zvirata | |
b = list(zvirata) | |
print(a) | |
print(b) | |
print(a==b) | |
print(a is b) | |
a = [] | |
if a: | |
print("není prázdný") | |
else: | |
print("je prázdný") |
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
hraci_pole = [] | |
for radek in range(3): | |
radek = [] | |
for sloupec in range(3): | |
radek.append('-') | |
hraci_pole.append(radek) | |
hraci_pole[0][0] = 'X' | |
hraci_pole[1][1] = 'X' | |
hraci_pole[2][2] = 'X' | |
for radek in hraci_pole: | |
print(radek) |
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
seznam = [1,2,3] | |
ntice = (1,2,3) | |
print(seznam) | |
print(ntice) | |
# ntice.append(4) | |
# ntice[1] = 6 | |
ntice = list(ntice) | |
print(ntice) | |
# print(list(ntice)) | |
# print(tuple(seznam)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment