Generetors

  • Create a list with all numbers from 1 to 20 
    • using list comprehension, create a list from the above with only the odd numbers
    • using list comprehension, create a list from the above multiple by 10 
  • Create a generator function to produce endless random numbers from a given range:

  • Add an option to change the range using send
  • Create a generator function to produce endless numbers from a given range in a circular flow :

  • Add an option to change the max number using send
  • Create a generator function to retrieve lines from log file in the following format:

The first char it the severity type (1-debug , 2-warning, 3-error)

  • The generator function gets 2 parameters: number of lines to retrieve and the severity type
  • Add an option to change the parameters using send 

Generators and  Classes

  • Create a class LogReader
  • Add members for number of lines and severity type
  • Add functions for set/get operations
  • Add a function gen() to retrieve a generator for log lines

Example use:

  • Add Exception handling (File not found, Access denied)
  • Add option to use the class only using “with” statement: