Can you do if else in list comprehension?

List comprehension in Python

Sooraj Parakkattil

Jun 21, 2020·3 min read

Photo by Mitchell Luo on Unsplash

Common applications are to make new lists where each element is the result of some operations applied to each member of another sequence or iterable or to create a subsequence of those elements that satisfy a certain condition.

  • List comprehension is an elegant way to define and create lists based on existing lists.
  • List comprehension is generally more compact and faster than normal

Video liên quan

Chủ Đề