Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
July 13, 2021 05:13 pm GMT

Python list comprehension

Ever use list comprehension in Python?

If not here is very beautiful use of list comprehension in Python which will make your code more neat and readable.

First of all what is list comprehension?

List comprehension is a syntax, list comprehension offer a shorter syntax when you want to create a new list based on the values of an existing list.

Here is the SYNTAX for it
[expression for item in iterable if condition == True]

Below I have shown two examples
One without using list comprehension and another with list comprehension.

Without list comprehension
Alt Text

With list comprehension
Alt Text


Original Link: https://dev.to/saifullah/python-list-comprehension-2o06

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To