<-^^->

Přednáška 5

Cvičení

  1. Write a function that takes list xs as one argument and a number y as the second argument. The function should return a new list ys with all numbers from xs bigger than y.
    Ukázkový vstup/výstup: [1,2,3,1,2,1,2,4,6,2], 3 => [4,6]
    řešení 1
  2. Write a function that takes list xs as an argument and returns list ys in which all the duplicates present in xs were removed.
    Ukázkový vstup/výstup: [1,2,3,1,2,1,2,4,6,2] => [1,2,3,4,6]
    řešení 1
  3. Write a function that takes list xs and item item and returns a list of all indexes of item in xs.
    Ukázkový vstup/výstup: [1,2,3,1,2,1,2,4,6,2], 2 => [1,4,6,9]
    řešení 1
  4. Write a function that takes list of integers xs and returns the first x, for which x has the same value as the following item. If no such item is found, return None.
    Ukázkový vstup/výstup: [0,3,4,5,5,4,2,2,4] => 5
    Ukázkový vstup/výstup: [0,3,4,5,4,2,4] => None
    řešení 1, řešení 2
  5. Write a function that takes list of integers xs and returns a list of x's, for which x has the same value as the following item.
    Ukázkový vstup/výstup: [0,3,4,5,5,4,2,2,4] => [5,2]
    Ukázkový vstup/výstup: [0,3,4,5,4,2,4] => []
    řešení 1
  6. Write a function that will take a filename as an argument and print the content of the corresponding file line by line. Make sure no extra empty lines are printed.
    řešení 1, řešení 2
  7. Modify the program so that it prints a line number at the beginning of each line.
    řešení 1
  8. Modify the program so that it prints the number of characters in the line at the beginning of each line.
    řešení 1
  9. Modify the function so that it takes a second argument. The function will then print only the lines from a file that contain the string given as second argument.
    řešení 1