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 to easily calculate the average of a list containing just … [Read more...] about Python: Average Of List Of Numbers – Without Imports [One-Liner]
one-liners
Check For Word In String: Python 1 Liner
How can you check if a word is found in a string using 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 to most using … [Read more...] about Check For Word In String: Python 1 Liner
Sort List Of Dictionaries By Key: Python 1 Liner
How can you sort a list of dictionaries by a key contained in each dictionary using Python? Can you do it in 1 line to show off your friends? Of course! To sort a list of dictionaries use the sorted() function with the key parameter set to a … [Read more...] about Sort List Of Dictionaries By Key: Python 1 Liner
Reverse Order Of List In Python Without For Loops (Examples, One-Liners, No Imports)
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 order of a list in Python use either the .reverse() list method which mutates the … [Read more...] about Reverse Order Of List In Python Without For Loops (Examples, One-Liners, No Imports)