list comprehension リスト内包表記

for ループで行うような短い操作を、一行で書く表現を、リスト内包表記という。たとえば、strsという文字列を要素とするリストがあるとて、リスト中の文字列を大文字にしたいとしよう。この処理は

strs_upper=[str1.upper() for str1 in strs]

で行うことができる。

The expression to write a short operation in a single line, without multiple lines with a for loop, is called "list comprehension". For example, suppose you have a list whose elements are the strings, and you want to capitalize the strings in the list. This is done by calling

strs_upper=[str1.upper() for str1 in strs]