List comprehension in Python
List comprehensions in Python are a powerful and concise way to create new lists based on existing iterables (like lists, tuples, strings, etc.). They offer a more compact alternative to traditional for loops with append. Syntax: new_list = [ expression for item in iterable [if condition ]] expression: This is what you want to do with each item in the iterable. It can be a simple variable representing the item, a calculation, a function call, or anything that evaluates to a value. item: This represents the variable that takes on the value of each item in the iterable as you loop through it. Think of it as a temporary variable for each iteration. iterable: This is the data source you're iterating over, like a list, tuple, string, or any object that can return its elements one at a time. condition (optional): This is an optional if clause that acts as a filter. Only items that meet the condition will be included in the new list. Here are some examples to illustrate differen