<s> import inspect <EOL> import json <EOL> import sys <EOL> from functools import wraps <EOL> from pygments import highlight <EOL> from pygments . lexers import PythonLexer <EOL> from pygments . lexers . data import JsonLexer <EOL> from pygments . formatters import TerminalFormatter <EOL> def pprint ( value ) : <EOL> formatted_value = highlight ( <EOL> json . dumps ( <EOL> value , <EOL> sort_keys = True , <EOL> indent = <NUM_LIT:4> , <EOL> separators = ( '<STR_LIT:U+002C>' , '<STR_LIT>' ) <EOL> ) , <EOL> JsonLexer ( ) , <EOL> TerminalFormatter ( bg = '<STR_LIT>' ) <EOL> ) <EOL> print ( formatted_value ) <EOL> def print_func ( func ) : <EOL> print ( "<STR_LIT>" ) <EOL> code = "<STR_LIT>" . join ( inspect . getsourcelines ( func ) [ <NUM_LIT:0> ] [ <NUM_LIT:1> : ] ) <EOL> print ( highlight ( code , PythonLexer ( ) , TerminalFormatter ( bg = '<STR_LIT>' ) ) ) <EOL> print ( "<STR_LIT>" ) <EOL> def print_func_result ( func ) : <EOL> print ( "<STR_LIT>" ) <EOL> result = func ( ) <EOL> if result is not None : <EOL> print ( "<STR_LIT>" . format ( result ) ) <EOL> print ( "<STR_LIT>" ) <EOL> def slide ( * args , ** kwargs ) : <EOL> def wrap ( f ) : <EOL> @ wraps ( f ) <EOL> def wrapped_f ( ) : <EOL> print_func ( f ) <EOL> sys . stdin . readline ( ) <EOL> if kwargs . get ( '<STR_LIT>' , False ) : <EOL> print_func_result ( f ) <EOL> sys . stdin . readline ( ) <EOL> return wrapped_f <EOL> if len ( args ) == <NUM_LIT:1> and callable ( args [ <NUM_LIT:0> ] ) : <EOL> return wrap ( args [ <NUM_LIT:0> ] ) <EOL> else : <EOL> return wrap <EOL> @ slide <EOL> def start ( ) : <EOL> """<STR_LIT>""" <EOL> @ slide ( executable = True ) <EOL> def dictionaries_1 ( ) : <EOL> """<STR_LIT>""" <EOL> my_dict = { '<STR_LIT>' : '<STR_LIT>' } <EOL> key = '<STR_LIT>' <EOL> if key in my_dict : <EOL> del my_dict [ key ] <EOL> if key in my_dict : <EOL> print ( my_dict [ key ] ) <EOL> else : <EOL> print ( "<STR_LIT>" ) <EOL> @ slide ( executable = True ) <EOL> def dictionaries_2 ( ) : <EOL> """<STR_LIT>""" <EOL> my_dict = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> print ( my_dict . pop ( '<STR_LIT>' , "<STR_LIT>" ) ) <EOL> print ( my_dict . pop ( '<STR_LIT>' , "<STR_LIT>" ) ) <EOL> print ( my_dict . pop ( '<STR_LIT>' , "<STR_LIT>" ) ) <EOL> pprint ( my_dict ) <EOL> @ slide ( executable = True ) <EOL> def dictionaries_3 ( ) : <EOL> """<STR_LIT>""" <EOL> my_dict = { <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> print ( my_dict . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> print ( my_dict . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> print ( my_dict . get ( '<STR_LIT>' ) ) <EOL> @ slide ( executable = True ) <EOL> def lists_1 ( ) : <EOL> """<STR_LIT>""" <EOL> my_list = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] <EOL> print ( my_list [ - <NUM_LIT:1> ] ) <EOL> @ slide ( executable = True ) <EOL> def lists_2 ( ) : <EOL> """<STR_LIT>""" <EOL> my_list = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:10> ] <EOL> start = <NUM_LIT:1> <EOL> end = <NUM_LIT:8> <EOL> step = <NUM_LIT:2> <EOL> pprint ( my_list [ start : end : step ] ) <EOL> pprint ( my_list [ end : start : - step ] ) <EOL> pprint ( my_list [ : : - <NUM_LIT:1> ] ) <EOL> @ slide ( executable = True ) <EOL> def lists_3 ( ) : <EOL> """<STR_LIT>""" <EOL> my_list_1 = [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' , '<STR_LIT:d>' , '<STR_LIT:e>' ] <EOL> my_list_2 = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] <EOL> print ( zip ( my_list_1 , my_list_2 ) ) <EOL> pprint ( dict ( zip ( my_list_1 , my_list_2 ) ) ) <EOL> @ slide ( executable = True ) <EOL> def and_or ( ) : <EOL> """<STR_LIT>""" <EOL> print ( "<STR_LIT>" ) <EOL> print ( True and False and None ) <EOL> print ( True and None and False ) <EOL> print ( True and <NUM_LIT:1> and <NUM_LIT:10> < <NUM_LIT:20> ) <EOL> print ( True and <NUM_LIT:10> < <NUM_LIT:20> and <NUM_LIT:1> ) <EOL> print ( "<STR_LIT>" ) <EOL> print ( True or False or None ) <EOL> print ( <NUM_LIT:1> or None or False ) <EOL> print ( False or None or <NUM_LIT:0> ) <EOL> print ( <NUM_LIT:0> or None or False ) <EOL> def my_wrong_append ( value , my_list = [ ] ) : <EOL> my_list . append ( value ) <EOL> return my_list <EOL> def my_append ( value , my_list = None ) : <EOL> my_list = my_list or [ ] <EOL> my_list . append ( value ) <EOL> return my_list <EOL> @ slide ( executable = True ) <EOL> def default_arguments_1 ( ) : <EOL> """<STR_LIT>""" <EOL> pprint ( my_wrong_append ( <NUM_LIT:1> ) ) <EOL> pprint ( my_wrong_append ( <NUM_LIT:2> ) ) <EOL> @ slide ( executable = True ) <EOL> def default_arguments_2 ( ) : <EOL> """<STR_LIT>""" <EOL> pprint ( my_append ( <NUM_LIT:1> ) ) <EOL> pprint ( my_append ( <NUM_LIT:2> ) ) <EOL> @ slide ( executable = True ) <EOL> def unpacking_1 ( ) : <EOL> """<STR_LIT>""" <EOL> a = '<STR_LIT>' <EOL> b = '<STR_LIT>' <EOL> a , b = b , a <EOL> print ( "<STR_LIT>" . format ( a , b ) ) <EOL> @ slide ( executable = True ) <EOL> def unpacking_2 ( ) : <EOL> """<STR_LIT>""" <EOL> point_a = ( <NUM_LIT:3> , <NUM_LIT:4> ) <EOL> point_b = { '<STR_LIT:y>' : <NUM_LIT:4> , '<STR_LIT:x>' : <NUM_LIT:3> } <EOL> print_point ( <NUM_LIT:3> , <NUM_LIT:4> ) <EOL> print_point ( * point_a ) <EOL> print_point ( ** point_b ) <EOL> @ slide <EOL> def unpacking_3 ( ) : <EOL> """<STR_LIT>""" <EOL> @ slide ( executable = True ) <EOL> def exceptions_1 ( ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> """<STR_LIT>""" <EOL> except : <EOL> pass <EOL> try : <EOL> """<STR_LIT>""" <EOL> except Exception : <EOL> pass <EOL> @ slide ( executable = True ) <EOL> def exceptions_2 ( ) : <EOL> try : <EOL> try : <EOL> raise KeyboardInterrupt ( ) <EOL> except Exception : <EOL> print ( "<STR_LIT>" ) <EOL> except : <EOL> print ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" ) <EOL> @ slide <EOL> def exceptions_3 ( ) : <EOL> """<STR_LIT>""" <EOL> @ slide ( executable = True ) <EOL> def flow_control_1 ( ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> a = <NUM_LIT:0> <EOL> except ValueError : <EOL> print ( "<STR_LIT>" ) <EOL> else : <EOL> print ( "<STR_LIT>" ) <EOL> finally : <EOL> print ( "<STR_LIT>" ) <EOL> @ slide ( executable = True ) <EOL> def flow_control_2 ( ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> a = <NUM_LIT:0> <EOL> except ValueError : <EOL> print ( "<STR_LIT>" ) <EOL> else : <EOL> print ( "<STR_LIT>" ) <EOL> return <NUM_LIT:1> <EOL> finally : <EOL> print ( "<STR_LIT>" ) <EOL> print <EOL> return <NUM_LIT:2> <EOL> def print_point ( x , y ) : <EOL> print ( "<STR_LIT>" . format ( x , y ) ) <EOL> @ slide ( executable = True ) <EOL> def chaining_comparisons ( ) : <EOL> """<STR_LIT>""" <EOL> x = <NUM_LIT:15> <EOL> y = <NUM_LIT:2> * x <EOL> print ( <NUM_LIT:10> < x < <NUM_LIT:20> < y < <NUM_LIT:50> ) <EOL> print ( <NUM_LIT:20> < x > <NUM_LIT:10> ) <EOL> @ slide <EOL> def web_server ( ) : <EOL> """<STR_LIT>""" <EOL> @ slide <EOL> def questions ( ) : <EOL> """<STR_LIT>""" <EOL> @ slide <EOL> def end ( ) : <EOL> """<STR_LIT>""" <EOL> slides = { <EOL> '<STR_LIT:start>' : ( start , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( dictionaries_1 , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( dictionaries_2 , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( dictionaries_3 , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( lists_1 , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( lists_2 , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( lists_3 , '<STR_LIT:3>' ) , <EOL> '<STR_LIT:3>' : ( and_or , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( default_arguments_1 , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( default_arguments_2 , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( unpacking_1 , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( unpacking_2 , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( unpacking_3 , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( exceptions_1 , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( exceptions_2 , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( exceptions_3 , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( flow_control_1 , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( flow_control_2 , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( chaining_comparisons , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( web_server , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( questions , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( end , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( exit , None ) , <EOL> '<STR_LIT:0>' : ( exit , None ) <EOL> } <EOL> def index ( ) : <EOL> r = "<STR_LIT>" <EOL> names = [ ] <EOL> keys = slides . keys ( ) <EOL> for k in sorted ( keys ) : <EOL> if hasattr ( slides [ k ] [ <NUM_LIT:0> ] , '<STR_LIT>' ) : <EOL> names . append ( '<STR_LIT>' . format ( <EOL> slides [ k ] [ <NUM_LIT:0> ] . __name__ , <EOL> k <EOL> ) ) <EOL> return '<STR_LIT:\n>' . join ( names ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> next_slide = '<STR_LIT:start>' <EOL> while True : <EOL> try : <EOL> print ( "<STR_LIT>" . format ( next_slide ) ) <EOL> user_input = sys . stdin . readline ( ) . strip ( '<STR_LIT:\n>' ) <EOL> if user_input == '<STR_LIT>' : <EOL> user_input = next_slide <EOL> func , next_slide = slides . get ( <EOL> user_input , <EOL> ( None , next_slide ) <EOL> ) <EOL> if func is exit : <EOL> sys . exit ( <NUM_LIT:0> ) <EOL> elif func is not None : <EOL> func ( ) <EOL> else : <EOL> print ( "<STR_LIT>" . format ( <EOL> user_input , <EOL> index ( ) <EOL> ) ) <EOL> except Exception : <EOL> raise <EOL> except : <EOL> sys . exit ( <NUM_LIT:0> ) </s>
