简体   繁体   中英

Is it possible to get rid of these loops?

Here are the two loops:

value = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
for i in range(10):
    if m[i] < max_iter:
        value[i] = 255

for i in range(10):
   draw.point((x[i], y), (hue[i], sat[i], value[i]))

These are two different problems, but might as well ask for both. So for the first one: Is it possible to set the values with the condition directly in a list (or tuple)? And for the second one: Is it possible to draw multiple points at once with the pillow module? I originally planned on putting all 10 points to be simultaneously drawn as a list as the first variable, which works, but I have problems to set their color value separately.

The first one works as a comprehension, but is harder to understand for beginners.

value = [255 if m[i] < max_iter else 0 for i in range(10)]

For drawing points the loop makes the most sense.

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