首页 > 解决方案 > 我想更改列表,使其连续两次具有相同的值

问题描述

我想更改列表,使其连续两次具有相同的值。正如您在下面看到的,目前没有覆盖 RGB 值。我想有两个相同的连续 RGB 值,但我不知道如何。如果你能告诉我如何做到这一点,我将不胜感激。

import seaborn as sns

def get_colorpalette(colorpalette, file_number):
    palette = sns.color_palette(
        colorpalette, file_number)
    rgb = ['rgb({},{},{})'.format(*[x*256 for x in rgb])
           for rgb in palette]
    return rgb
['rgb(220.16,95.0272,87.03999999999999)',
 'rgb(220.16,167.6381090909091,87.03999999999999)',
 'rgb(200.0709818181818,220.16,87.03999999999999)',
 'rgb(127.46007272727276,220.16,87.03999999999999)',
 'rgb(87.03999999999999,220.16,119.23083636363639)',
  ・
  ・
  ・

['rgb(220.16,95.0272,87.03999999999999)',
 'rgb(220.16,95.0272,87.03999999999999)',
 'rgb(220.16,167.6381090909091,87.03999999999999)',
 'rgb(220.16,167.6381090909091,87.03999999999999)',
 'rgb(200.0709818181818,220.16,87.03999999999999)',
 'rgb(200.0709818181818,220.16,87.03999999999999)',
  ・
  ・
  ・

标签: pythonlistseaborn

解决方案


使用 for 循环可以轻松完成。我使用字符作为元素,因为最终列表中的元素也是字符串。

a = ['a', 'b', 'c']
aa = []
for i in a:
    aa.append(i)
    aa.append(i)
aa
['a', 'a', 'b', 'b', 'c', 'c']

推荐阅读