>>> l = [22, 13, 45, 50, 98, 69, 43, 44, 1]
>>> [x+1 if x >= 45 else x+5 for x in l]
[27, 18, 46, 51, 99, 70, 48, 49, 6]
Do-something if <condition>
, else do-something else.
More Related Contents:
- List comprehensions
- How to create the following lists with list comprehensions? [closed]
- Find a unique element in a list [closed]
- What does “list comprehension” and similar mean? How does it work and how can I use it?
- How to find all occurrences of an element in a list
- Pythonic way to print list items
- List comprehension with if statement
- Transpose a matrix in Python [duplicate]
- Why is a list comprehension so much faster than appending to a list?
- Python’s most efficient way to choose longest string in list?
- List comprehension vs generator expression’s weird timeit results?
- How to unzip a list of tuples into individual lists? [duplicate]
- list() uses slightly more memory than list comprehension
- Appending item to lists within a list comprehension
- How to frame two for loops in list comprehension python
- How to return a subset of a list that matches a condition [duplicate]
- Python using enumerate inside list comprehension
- Nested list comprehensions
- How to remove multiple items from a list in just one statement?
- list.extend and list comprehension [duplicate]
- Comprehension on a nested iterables?
- remove None value from a list without removing the 0 value
- How can I use list comprehensions to process a nested list?
- sum each value in a list of tuples
- Duplicate elements in a list [duplicate]
- flatten list of list through list comprehension
- Converting List Comprehensions to For Loops in Python
- Creating a Python list comprehension with an if and break
- Optimal method to find the max of sublist items within list
- Skip elements on a condition based in a list comprehension in python