2021年3月8日星期一

Updating Output List

I created the following code, where the goal is to create a different color filter for every 1/3 of a tuple list:

def color_filter(x):  for i in x:      for n, pix in enumerate(i):          new = ((pix[0]+pix[1]+pix[2])//3, 0, 0), (0, (pix[0]+pix[1]+pix[2])//3, 0), (0, 0, (pix[0]+pix[1]+pix[2])//3)          i[n] = new  return x  

where x = [[(84, 0, 153), (84, 0, 153), (84, 0, 153)], [(177, 219, 255), (177, 219, 255), (177, 219, 255)]]

I want the code to output [[(79, 0, 0), (0, 79, 0), (0, 0, 79)], [(217, 0, 0), (0, 217, 0), (0, 0, 217)]] but it outputs [[((79, 0, 0), (0, 79, 0), (0, 0, 79)), ((79, 0, 0), (0, 79, 0), (0, 0, 79)), ((79, 0, 0), (0, 79, 0), (0, 0, 79))], [((217, 0, 0), (0, 217, 0), (0, 0, 217)), ((217, 0, 0), (0, 217, 0), (0, 0, 217)), ((217, 0, 0), (0, 217, 0), (0, 0, 217))]] instead. How can I fix this?

https://stackoverflow.com/questions/66540491/updating-output-list March 09, 2021 at 11:44AM

没有评论:

发表评论