
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
37 lines
840 B
Plaintext
37 lines
840 B
Plaintext
== Why is this an issue?
|
|
|
|
There are several ways to create a new list based on the elements of some other collection, but the use of a list comprehension has multiple benefits. First, it is both concise and readable, and second, it yields a fully-formed object without requiring a mutable object as input that must be updated multiple times in the course of the list creation.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,python]
|
|
----
|
|
squares = []
|
|
for x in range(10):
|
|
squares.append(x**2) # Noncompliant
|
|
|
|
squares = map(lambda x: x**2, range(10)) #Noncompliant
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,python]
|
|
----
|
|
squares = [x**2 for x in range(10)]
|
|
----
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Use a comprehension here instead.
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|