Python is praised for its ability to create code that is both elegant and easy to understand. One of its standout features is list comprehension, which lets us write powerful functionality in just a single line. However, some Python developers find it challenging to use list comprehension to its full potential. Overusing list comprehension can lead to less efficient and harder-to-read code.
Example of List comprehension in Python
List Comprehension syntax below followed by a example how to use it
newlist = [expression for item in iterable if condition == True]
Person = ["Priya", "Hira", "Rudra", "Badsha", "Lion"]
newlist = [x for x in Person if "i" in x]
print(newlist)
Top comments (0)