# -*- coding: utf-8 -*- """loops.ipynb Automatically generated by Colaboratory. Original file is located at https://colab.research.google.com/drive/1I-Okj_eE9P9GHPo3xJdO7eYHsFa7Kqs1 # If, Elif a Else """ x = int(input('Type number: ')) x = 2 if x > 6 == 0: print(x, 'je vic') if x == 5: print('pet') elif x < 6: print(x, 'je mene') else: print("A to je dobre.") if 4 in [4, 5, 6]: print('je tam') """# Range""" list(range(10)) list(range(0, 10, 2)) """# For""" for i in range(3): print(i) for letter in 'python': if letter == 'p': print('') else: print(letter) for i, letter in enumerate('python'): print(i, 'ty letter je ', letter) for letter in 'python': if letter == 'p': break else: print(letter) print('end loop') x = 1 while x > 0: x += 1 print(x) """# List comprehension""" list_comprehen="""numbers =[0, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4] odd_numbers = [x for x in numbers if x % 2 == 1] # {x| x nalezi numbers a ma zbytek 1 po deleni 2} """ import timeit timeit.timeit(list_comprehen) classic="""numbers = [0, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4] odd_numbers_long = [] for x in numbers: if x % 2 == 1: odd_numbers_long.append(x)""" timeit.timeit(classic) our_dict = {x: x>2 for x in numbers} """NEPOUZIVAT KLICOVA SLOVA PYTHONU JAKO PROMENE JINAK SE Z TOHO ZBLAZNITE viz str !""" str(3) str {x: "Ano" for x in our_dict.values()} {y: x for x, y in our_dict.items()} [x for x in our_dict.items()] for x in our_dict.values: print(x) ## POZOR values, items, keys ap. jsou slovnikove METODY a tedy je treba je zavolat, konci ()