How To Create A List With Values: Python Code (Examples, One-Liners, No Imports)
You can construct a list in a certain number of ways as detailed in the Python documentation. The most popular I use the most is by defining my list variables …
You can construct a list in a certain number of ways as detailed in the Python documentation. The most popular I use the most is by defining my list variables …
To remove an individual item from a list in Python you can use either a list method or the del statement, both approaches mutate the original list – meaning the …
To sort a list of strings according to their length, use a lambda function on the key parameter with the lambda function using the len function on each element. This …
To convert a string to an integer you use the handy int() function. For example, if you have a string such as “79” and you insert this like so into …
Recently, I had an exercise where I needed to flatten a two-dimensional list down to just one dimension, something where I needed the result to be like this: There were …
In Python there is a handy function to determine the data type of any variable, and it is aptly called type(). This function can help to assess whether a variable …
There have been times when I wanted to perform a simple for-loop filter operation on a list, and I’ve often wondered if there’s a quick and simple way to do …
In my previous article where I found the average of a list in Python without using imports, in this article I want to expand how you could apply the same …
How do you sort a two-dimensional list in Python easily without importing libraries? Thankfully, there are some native functions in Python which make sorting lists a breeze. I recently had …
How do you calculate the simple average of a list of numbers in Python, without needing to import any libraries? Unfortunately, there’s no native average or avg function in Python …
Recently, I had an issue where I wanted to exclude strings from a list if they contained a certain word. I thought I could use the following common code familiar …
Moving on from my previous post where I was sorting a list after the second element on, I now needed to sort the list of dictionaries by their values. If …
I had a recent need while programming in Python where I needed to sort after the second element onwards. I was outputting a CSV file from a List[Dict] and I …
There have been times when after creating a list in Python I’ve wanted to sort a list and then have the list reversed from ascending to descending. To reverse the …
In Microsoft Word you can control whether or not you want to see the white space characters in your document. This helps to check you haven’t incorrectly inserted a tab …
How many ways can you skin a string? In this article we will look at several ways to remove a character from a string using Python.
After moving my blog to Hugo and then back to WordPress, I knew there would be a few broken links on my website. The question I asked myself was: How …