The Matrix Find Algorithm in Python

What is the output of this code snippet? The challenge is shifting from understanding syntactical to semantical code snippets and algorithms. If you thoroughly master these types of code puzzles, you will join the club of advanced coders. Thus, you open up the opportunity to work in one of the highest paid job industry in …

The Matrix Find Algorithm in Python Read More »

The Range Function and Indexing in Python

What is the output of this code snippet?   [python] print(range(5, 10)[-1]) print(range(0, 10, 3)[2]) print(range(-10, -100, -30)[1]) [/python]   If this book can teach you only one thing, it is a thorough understanding of the most important Python concepts such as indexing and slicing. I can not emphasize enough how important these concepts are …

The Range Function and Indexing in Python Read More »

Replacing Default Parameters in Python

Is ask_ok(‘Howdy?’, 5) a valid function call?   [python] def ask_ok(prompt, retries=4, reminder=’Repeat!’): while True: ok = input(prompt) if ok in (‘y’, ‘ye’, ‘yes’): return True if ok in (‘n’, ‘no’, ‘nop’, ‘nope’): return False retries = retries – 1 if retries < 0: raise ValueError(‘invalid user response’) print(reminder) [/python]   This puzzle introduces the …

Replacing Default Parameters in Python Read More »

Slice Assignment in Python

What is the output of this code snippet?   [python] customers = [‘Marie’, ‘Anne’, ‘Donald’] customers[2:4] = [‘Barack’, ‘Olivia’, ‘Sophia’] print(customers[2:-1]) [/python]   A great coder seeks the cleanest and shortest way to accomplish his goals. This puzzle demonstrates a Python trick that I found very useful: slice assignments. Suppose you work in a biotech …

Slice Assignment in Python Read More »