Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我想更改列表,使其在一行中有两次相同的值_Python_List_Seaborn - Fatal编程技术网

Python 我想更改列表,使其在一行中有两次相同的值

Python 我想更改列表,使其在一行中有两次相同的值,python,list,seaborn,Python,List,Seaborn,我想更改列表,使其在一行中有两次相同的值。 如下所示,RGB值中当前没有覆盖范围。我想有两个连续的RGB值是相同的,但我不知道如何。 如果你能告诉我怎么做,我将不胜感激 import seaborn as sns def get_colorpalette(colorpalette, file_number): palette = sns.color_palette( colorpalette, file_number) rgb = ['rgb({},{},{})

我想更改列表,使其在一行中有两次相同的值。 如下所示,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

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

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

需要明确的是:是否要重复输入中的每个值?当你说“目前RGB值中没有覆盖范围”时,我不明白你的意思。这里的“覆盖率”是什么?你的意思是
rgb=[y代表x,rgb代表y,rgb代表y在[x,x]]
?还是仅仅
np.重复(rgb,2)
['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)',
  ・
  ・
  ・
a = ['a', 'b', 'c']
aa = []
for i in a:
    aa.append(i)
    aa.append(i)
aa
['a', 'a', 'b', 'b', 'c', 'c']