You are on page 1of 10

Algoritma dan

Pemrograman

List
Comprehension

Adi
adi4vista@gmail.com
List Comprehensions
• List : [1, 2, “a”, 3.14]
• List Comprehensions:
– alternative cara untuk membuat/membentuk list
dengan menggunakan expression.
– bentuk umum:
• [transform iteration filter]
– [expr for val in collection]
– [expr for val in collection if <test>]
– [expr for val in collection if <test1> and <test2>]
– [expr for val1 in collection1 for val2 in collection2]
examples
examples
examples
examples
examples
examples

You might also like