Session Ready
Exercise

List comprehension

List comprehensions are a concise and convenient way to address a common programming task: iterating though a list, making a calculation, and saving the calculation into a new list. While this can be performed using a for loop, a list comprehension preforms the same task with fewer number of lines.

The following list comprehension squares all values in a list:

x = [1, 2, 3, 4]
print([i**2 for i in x])

[1, 4, 9, 16]

A list of file names has been provided to you in the inflam_files list. Your task is to write a list comprehension that imports these files as pandas DataFrames in a single list.

Instructions
100 XP
  • Re-write the provided for loop as a list comprehension: dfs_comp.