Most of you might be too young to know this but there was time that the phone in your house - not in your pocket! - would ring and gasp! you had no idea who was calling! You had to ANSWER the phone to find out. š¤¦āāļø Now we have caller ID and know exactly … Continue reading A caller id for your python function
Tag: python
Getting started with gRPC – part II: the code
In a previous post I wrote a summary of the things I learned about gRPC. Here I will talk about the prototype app I wrote to test gRPC and gRPC-Web. About my prototype As I mentioned before, I wrote a prototype app that tests if the string that the user typed in the browser is … Continue reading Getting started with gRPC – part II: the code
Getting started with gRPC – part I: the what
I recently spent some time researching gRPC and this post is a summary of what I learned. I also wrote a prototype application to test gRPC and gRPC-Web with Python and JS. The JS client takes a string from user input and test if it's a palindrome. The code can be found on GitHub and … Continue reading Getting started with gRPC – part I: the what
Do I need to indent my Python code? What about JavaScript?
Yes! Indentation, or leading white space at the beginning of a line is required in Python. You can read more about why that is important here. And here is the part of the style guide convention for indentation (PEP 8). In JavaScript on the other hand, white space is added for readability only but it … Continue reading Do I need to indent my Python code? What about JavaScript?
Difference among list, tuple and set in Python and when to use each one
Python has three similar data structures that can hold an unordered collection of elements: list, tuple and set. Here's how they differ: initialization list: using the built-in list() or the square brackets ([]): list1 = list() # creates an empty list list2 = [] # also creates an empty list list3 = ['a', 'b', 'c', … Continue reading Difference among list, tuple and set in Python and when to use each one
Add a filename in the command line when running a Python script
OR: Run a Python script with arguments You can add arguments to the command line when running python scripts by importing the sys module from Python's standard library and using its argv function. Some examples: A simple script that displays the user name: def main(): name = 'Frodo' print(f'Hello, {name}') if __name__ == "__main__": main() … Continue reading Add a filename in the command line when running a Python script
Display nested dictionary content sorted by key in Python
Given a nested dictionary like this: dog_breeds = { 'Labrador Retriever': {'life_span': 14, 'male_weight': '36 Kg', 'female_weight': '32 Kg'}, 'Beagle': {'life_span': 15, 'male_weight': '11 Kg', 'female_weight': '10 Kg'}, 'German Shepherd': {'life_span': 13, 'male_weight': '40 Kg', 'female_weight': '32 Kg'}, 'Jack Russell Terrier': {'life_span': 16, 'male_weight': '8 Kg', 'female_weight': '8 Kg'}, 'Rottweiler': {'life_span': 10, 'male_weight': '60 Kg', … Continue reading Display nested dictionary content sorted by key in Python
Profiling: check how long it takes to run a Python script
From Python's official documentation: "AĀ profileĀ is a set of statistics that describes how often and for how long various parts of the program executed." Python's standard library provides two implementations of the same profiling interface: cProfile and profile but I always go with cProfile for short scripts because you can invoke it at run time like … Continue reading Profiling: check how long it takes to run a Python script
Map a string in Python with enumerate
Problem: create a map of the letters and indicesĀ in a string. My first approach was to loop over the string using range(len(s)), and checking if the letter exists in the map before adding it: s = 'mozzarella' mapped_s = {} for i in range(len(s)): if s[i] in mapped_s: mapped_s[s[i]].append(i) else: mapped_s[s[i]] = [i] print(f' mapped: … Continue reading Map a string in Python with enumerate
Hello world!
UPDATE: At the time this post was published the blog's name was print(f'{greeting}') What does this blog name mean? I'm glad you asked! It's python's string interpolation. Say that you have a variable greeting, set to 'Hello world': greeting = 'Hello world' Well, the blog name then, you guessed, would resolve to 'Hello world'.