Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python list comprehension

 # A list comprehnsion is a for loop on a single line 
 # To create a list comprehension, swap the two lines in the for loop.

# Here we use PyBIDS to extract the relative path for each file:
for fmri in fmri_078:
    print(fmri.relpath)

# And here is the equivalent statement as a list comprehension.
# It must be enclosed in square brackets.
# It swaps the order of the lines and loses the colon and indentation
[ print(fmri.relpath) for fmri in fmri_078 ]   
Source by www.codegrepper.com #
 
PREVIOUS NEXT
Tagged: #python #list #comprehension
ADD COMMENT
Topic
Name
9+8 =