Daily Python Puzzle

A Simple Formula to Reach Any Success

Yesterday, I found this email in my INBOX — sent by Finxter Muhammad, one of my most loyal “Coffee Break Python” email readers: ~~~ I have good news I got a job as a Python programmer in a software house.All credit goes to you – Your daily puzzles made me good in Python….. ~~~ While …

A Simple Formula to Reach Any Success Read More »

How to Get Rid of Python’s Map Function With List Comprehension

You may have read that Python’s godfather, Guido van Rossum, doesn’t like the map() function too much. He argues that it can be easily replaced with list comprehension which is not only faster but also more readable and shorter. Here’s an example: You can solve the puzzle on the interactive Finxter app before reading on …

How to Get Rid of Python’s Map Function With List Comprehension Read More »

A List of Lambda Functions? This Python Puzzle May Surprise You…

Guido doesn’t like lambda functions too much. Yet, most large code projects contain a lot of them! (Many coders use lambda functions as GUI callbacks, etc.) In this “Coffee Break Python” email series, we take a pragmatic approach regarding Python code style — living in the “is” rather than in the “should be” world. Can …

A List of Lambda Functions? This Python Puzzle May Surprise You… Read More »

Python Puzzle Discover

10 Best Python Puzzles to Discover Your True Skill Level

Do you belong to the top 50% of Python coders? This article poses you 10 intermediate-level Python puzzles to test yourself. By solving all 10 Python puzzles and tracking your success rate, you will discover your exact Python skill level. How to do this? The idea of solving rated Python puzzles to measure your skill …

10 Best Python Puzzles to Discover Your True Skill Level Read More »

[Basics Computer Science] A Recursive Pathfinder Algorithm in Python

def find_path(graph, v_start, v_end, path_len=0): '''Is there a path between vertex v_start and vertex v_end?''' # Traverse each vertex only once if path_len >= len(graph): return False # Direct path from v_start to v_end? if graph[v_start][v_end]: return True # Indirect path via neighbor v_nbor? for v_nbor, edge in enumerate(graph[v_start]): if edge: # between v_start and …

[Basics Computer Science] A Recursive Pathfinder Algorithm in Python Read More »

A Case for Puzzle-based Learning Python

Overcome the Knowledge Gap The great teacher Sokrates delivered complex knowledge by asking a sequence of questions. Each question was building on answers to previous questions provided by the student. This more than 2400 year old teaching technique is still in wide-spread use today. A good teacher opens a gap between their’s and the learner’s …

A Case for Puzzle-based Learning Python Read More »

Daily Data Science Puzzle: How to Get the Shape of a Numpy Matrix?

What is the output of this puzzle?   import numpy as np # salary in ($1000) [2015, 2016, 2017] dataScientist = [133, 132, 137] productManager = [127, 140, 145] designer = [118, 118, 127] softwareEngineer = [129, 131, 137] a = np.array([dataScientist, productManager, designer, softwareEngineer]) print(a.shape[0]) print(a.shape[1])   Numpy is a popular Python library for …

Daily Data Science Puzzle: How to Get the Shape of a Numpy Matrix? Read More »

Daily Python Puzzle: How to Intersect two Sets in Python?

What is the output of this puzzle? # cancer-fighting foods cf = {"basil", "berries", "broccoli", "curcume", "garlic", "kale", "oranges", "seeds", "spinach", "sprouts"} # blood pressure reducing foods bf = {"bananas", "berries", "fish", "garlic", "kale", "red beets", "salmon", "seeds", "spinach", "yogurt"} print(len(cf & bf)) This puzzle is about two pieces of basic knowledge. The first piece …

Daily Python Puzzle: How to Intersect two Sets in Python? Read More »

Daily Python Puzzle: How to Find the Maximum in a Dictionary?

What is the output of this puzzle?   # mg per 100g omega3_table = { "Salmon" : 2260, "Hering" : 1729, "Sardines" : 1480, "Flaxseeds" : 53400, "Eggs" : 400 } y = max(omega3_table, key=lambda x : omega3_table[x]) print(y)   In this puzzle, we learn two things. First, we can retrieve the maximal element of …

Daily Python Puzzle: How to Find the Maximum in a Dictionary? Read More »