简体   繁体   中英

How can I put the various elements come from for loop in a list?

['aba']['b']['c']

These above element came while iterating in a loop and I want to make a list which contains these elements. How can I achieve my goal?

Make an empty list and then append results to that list. For example:

loop = [1, 2, 3, 4, 5, 6]
endresult = []
for i in loop:
    if i % 2 == 0:
        endresult.append(i)

Output:

[2, 4, 6]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM