# List Comprehensions and Built-In Functions on Lists

In this lesson, you’ll learn how to use list comprehensions to construct various lists, and different list methods to manipulate lists.

List comprehensions are a useful way to construct lists on the fly. They use the following syntax:

``````[<expr> for <elem> in <lst> if <cond>]
``````

Here’s an example:

>>>
``````>>> [(lambda x: x *x )(x) for x in [1, 2, -5, 4]]
[1, 4, 25, 16]
``````

They’re used in place of functions like `map()` and `filter()`. To learn more, check out Using List Comprehensions Effectively.

There are also some useful built-in functions that can be applied to lists such as `max()`, `min()`, `any()`, and `all()`:

• `max()` finds the maximum value of an iterable using the built-in `cmp()` method, or the `key` param.
• `min()` finds the minimum value of an iterable using the built-in `cmp()` method, or the `key` param.
• `any()` returns whether any of the elements in the iterable are a `true` value.
• `all()` returns whether all of the elements in the iterable are `true` values. Piotr

I wonder what’s the benefit of using

``````[(lambda x: x % 2 == 1)(num) for num in l]
``````

over simply

``````[bool(num % 2) for num in l]
``````

? James Uejio RP Team

@Piotr Good point! Either is fine in my opinion, bool() will assume that the user knows that 0 is a False value in Python (some languages it might be a True value), while lambda is more explicit. MichaelKareev

Probably it’s even more Pythonic for squaring list’s elements:

``````[x**2 for x in lst]
``````

to join the conversation.