How to Read the First Line of a File in Python

Problem Formulation and Solution Overview This article will show you how to read and display the first line of a file in Python. For this article, we will work with a flat-text file containing five (5) possible things to do during your lifetime. This file is saved to bucket_list.txt and placed into the current working … Read more

Python Convert String List to Uppercase

Coding Challenge πŸ₯‹ πŸ’¬ Question: How to convert a list of strings to all uppercase in Python? Here are three examples: [‘hello’, ‘Python’, ‘world’] to [‘HELLO’, ‘PYTHON’, ‘WORLD’] [‘a’, ‘b’, ‘c’] to [‘A’, ‘B’, ‘C’] [‘aa aa’, ‘bb$bb’, ‘cc()cc’] to [‘AA AA’, ‘BB$BB’, ‘CC()CC’] There are multiple great ways to accomplish this coding challenge and … Read more

Python Convert String List to Lowercase

Coding Challenge πŸ₯‹ πŸ’¬ Question: How to convert a list of strings to all lowercase in Python? Here are three examples: [‘HELLO’, ‘Python’, ‘world’] to [‘hello’, ‘python’, ‘world’] [‘A’, ‘B’, ‘C’] to [‘a’, ‘b’, ‘c’] [‘AA AA’, ‘BB$BB’, ‘CC()CC’] to [‘aa aa’, ‘bb$bb’, ‘cc()cc’] There are multiple great ways to accomplish this coding challenge and … Read more

Python – Split String After K-th Occurrence of Separator

Coding Challenge πŸ’¬ Question: Given a Python string. How to split the string after the k-th occurrence of the separator (string or character)? In other words: how to ignore the first (k-1) separator occurrences when splitting a string? Here are three examples: πŸ‘‰ Related Tutorial: Python Split String After Second Occurrence Solution You can split … Read more

How to Print a NumPy Array Without Scientific Notation in Python

Problem Formulation Β» Problem Statement: Given a NumPy array. How to print the NumPy array without scientific notation in Python? Note: Python represents very small or very huge floating-point numbers in their scientific form. Scientific notation represents the number in terms of powers of 10 to display very large or very small numbers. For example, … Read more

Python – Split String After Second Occurrence of Separator

Coding Challenge πŸ’¬ Question: Given a Python string. How to split the string after the second occurrence of the separator (string or character)? In other words: how to ignore the first separator occurrence when splitting a string? Here are three examples: ‘a-b-c-d-e-f-g-h’ and sep=’-‘ should be split to [‘a-b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘h’] … Read more

TypeError Built-in Function or Method Not Subscriptable (Fixed)

Overview 🌞 Do you encounter this stupid error? TypeError: ‘builtin_function_or_method’ object is not subscriptable You’re not alone—thousands of coders like you experience this error in thousands of projects every month. This short tutorial will show you exactly why this error occurs, how to fix it, and how to never make the same mistake again. So, … Read more

How to Count the Number of Unique Values in a List in Python?

Problem Statement:Β Consider that you have been given a list in Python. How will you count the number of unique values in the list? Example: Let’s visualize the problem with the help of an example: Given:Β li = [‘a’, ‘a’, ‘b’, ‘c’, ‘b’, ‘d’, ‘d’, ‘a’]Output:Β The unique values in the given list are ‘a’, ‘b’, ‘c’, ‘d’. … Read more

The Art of Clean Code [Book Reviews]

On this page, I’ll collect selected reader feedback for my newest book πŸ“• “The Art of Clean Code” (Amazon, NoStarch). I’ll only share the feedback from readers who explicitly agreed to publish it here. πŸ‘‰ Want to Get Featured Here? Feel free to send in your feedback by replying to any of my emails. “Cannot … Read more