-
-
Save hernikplays/1e0b5b13dc28a804ceeae768928dc527 to your computer and use it in GitHub Desktop.
listy
This file contains 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
def change_num(arr, num1, num2): | |
# možná by stačilo upravit původní "arr", ale já to dělám na jistotu | |
novy = [] | |
for x in arr: | |
if x == num1: # když je x rovno num1 | |
novy.append(num2) # do nového listu vložíme num2 | |
else: # jinak vložíme číslo původní | |
novy.append(x) | |
return novy # a vrátíme | |
print(change_num([1,2,3,74,5,6,8,7,9],7,0)) |
This file contains 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
def every_second_number(num_list): | |
print(num_list[0]) | |
i = 2 # pomocná proměnná | |
while True: | |
print(num_list[i]) # vypíše | |
i+=2 # přičítáme po dvou, abychom šli po dvou lol | |
if(i>len(num_list)): | |
break # když jsme na konci, zastavíme (možná šel používat for in range lol) | |
every_second_number([0,1,2,3,4,5,6,7,8,10,9]) |
This file contains 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
def unique(mylist): | |
novy = [] | |
for x in mylist: | |
if x in novy: # pokud x je již v listu "novy", pokračujeme a nic nepřidáváme | |
continue | |
else: # jinak vkládáme | |
novy.append(x) | |
return novy | |
print(unique([0,1,2,3,1,3,5,64,8,0,10,52])) |
This file contains 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
def find_longest_words(wordslist): | |
nejdelsi = "" | |
for x in wordslist: | |
if len(x)>len(nejdelsi): # jednoduše měříme délku a následně uložíme | |
nejdelsi = x | |
return nejdelsi | |
print(find_longest_words(["slon","žirafa","pes","drevokocúr","liška"])) |
This file contains 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
def max_pair_sum(num_list): | |
nej = 0 | |
for i,p in enumerate(num_list): # enumerate v podstatě udělá to, že "i" bude index u kterého právě jsme a "p" je ta hodnota, zde číslo z num_list | |
if(i+1 == len(num_list)): # tohle je brzda abychom nepracovali s posledním číslem | |
break | |
if(p+num_list[i+1] > nej): # když je sečtené číslo větší než aktuálně nějvětší, uložíme (dávám "i+1", protože i by odkazovalo na aktuální číslo | |
nej = p+num_list[i+1] | |
return nej | |
print(max_pair_sum([2,5,6,0,3,4,9,15,2,51,6,3])) |
This file contains 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
def nonzero_product(*numbers): | |
soucin = 1 | |
for x in numbers: | |
if x != 0: # x nesmí být 0 | |
soucin *= x # přisoučiníme | |
return soucin | |
print(nonzero_product(1,2,3,5,4,9,3,0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment