Print a List Without Quotes in Python – 5 Best Ways

Problem Formulation 💬 How to print a list without quotes in Python? Given a Python list of strings such as [‘1’, ‘2’, ‘3’]. If you print the list to the shell using print([‘1’, ‘2’, ‘3’]), the output is enclosed in square brackets and the strings have quotes like so: “[‘1’, ‘2’, ‘3’]”. This article will … Read more

How to Find the Shortest String in a Python List?

Use Python’s built-in min() function with a key argument to find the shortest string in a list. Call min(lst, key=len) to return the shortest string in lst using the built-in len() function to associate the weight of each string—the shortest string will be the minimum. Problem Formulation Given a Python list of strings. Find the … Read more

How to Find the Longest String in a Python List?

Use Python’s built-in max() function with a key argument to find the longest string in a list. Call max(lst, key=len) to return the longest string in lst using the built-in len() function to associate the weight of each string—the longest string will be the maximum. Problem Formulation Given a Python list of strings. Find the … Read more

How to Apply a Function to Each Cell in a Pandas DataFrame?

Problem Formulation Given the following DataFrame df: 💬 Challenge: How to apply a function f to each cell in the DataFrame? For example, you may want to apply a function that replaces all odd values with the value ‘odd’. Solution: DataFrame applymap() The Pandas DataFrame df.applymap() method returns a new DataFrame where the function f … Read more

Python – How to Convert KML to CSV?

What is KML? ℹ️ Definition: The Keyhole Markup Language (KML) is a file format for displaying geographic data in Google Earth or other so-called “Earth Browsers”. Similarly to XML, KML uses a tag-based structure with nested elements and attributes. How to Convert KML to CSV in Python? You can convert a .kml to a .csv … Read more

Python Convert GeoJSON to CSV

What is GeoJSON? 💡 GeoJSON is an RFC standardized data format to encode geographic data structures such as Point, LineString, Polygon, MultiPoint, MultiLineString, and MultiPolygon. GeoJSON is based on the JavaScript Object Notation (JSON). Example GeoJSON to CSV Say, you have the following GeoJSON snippet: You want to convert it to the following CSV format: … Read more

Python Convert Fixed Width File to CSV

What is a Fixed-Width File? 💡 Definition: A fixed-width text file contains data that is structured in rows and columns. Each row contains one data entry consisting of multiple values (one value per column). Each column has a fixed width, i.e., the same number of characters, restricting the maximum data size per column. Example of … Read more