python - 我想更改列表,使其连续两次具有相同的值
问题描述
我想更改列表,使其连续两次具有相同的值。正如您在下面看到的,目前没有覆盖 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)',
・
・
・
解决方案
使用 for 循环可以轻松完成。我使用字符作为元素,因为最终列表中的元素也是字符串。
a = ['a', 'b', 'c']
aa = []
for i in a:
aa.append(i)
aa.append(i)
aa
['a', 'a', 'b', 'b', 'c', 'c']
推荐阅读
- c# - 32 位客户端和 64 位服务器之间的免注册 COM 互操作
- asp.net - 允许未经身份验证访问 ASP.NET web.config 中的某些文件类型,无论其位置如何
- python - 如果他们第一次弄错了,有没有办法不给分,测验,python
- python - 如何将 df 值与列表的元素进行比较,并用这些值制作 df?
- python - 如何让 pylint 在全局范围内忽略单个模块的未使用导入?
- python - 如何从 SQL Server 表中提取日期并将其存储在 Pandas 的变量中,没有噪音,只有日期
- floating-point - 如何在不使用宏或反复试验的情况下找到用于浮点数的基数
- c# - C# Coverlet 结果始终为空
- pandas - 在 Python/Pandas 中循环通过两个 csv 相同的代码仅适用于其中一个文件
- php - 另一种方法使异步 REST API 与 laravel 没有 ajax