是否有内置功能可以从Python中的列表中删除重复项,同时保留顺序?我知道我可以使用一个集来删除重复项,但这会破坏原始顺序.我也知道我可以像这样滚动自己:
def uniq(input):
output = []
for x in input:
if x not in output:
output.append(x)
return output
Run Code Online (Sandbox Code Playgroud)
但是如果可能的话,我想利用内置或更多的Pythonic习语.
使用Python 3.x,我有一个字符串列表,我想对其执行自然的字母排序.
自然排序: Windows中文件的排序顺序.
例如,以下列表是自然排序的(我想要的):
['elm0', 'elm1', 'Elm2', 'elm9', 'elm10', 'Elm11', 'Elm12', 'elm13']
Run Code Online (Sandbox Code Playgroud)
这是上面列表的"排序"版本(我有):
['Elm11', 'Elm12', 'Elm2', 'elm0', 'elm1', 'elm10', 'elm13', 'elm9']
Run Code Online (Sandbox Code Playgroud)
我正在寻找一个行为与第一个类似的排序函数.
有什么方法可以在 Seaborn 中创建区域图。我查看了文档,但找不到。
这是我想要绘制的数据。
year_countries.head()
Out[19]:
state_code China France Japan Russia United States
launch_year
1957 0 0 0 2 1
1958 0 0 0 5 22
1959 0 0 0 4 18
1960 0 0 0 8 29
1961 0 0 0 9 41
Run Code Online (Sandbox Code Playgroud)
我使用此代码创建了一个线图 -
sns.relplot(data=year_countries, kind='line',
height=7, aspect=1.3,linestyle='solid')
plt.xlabel('Lanuch Year', fontsize=15)
plt.ylabel('Number of Launches', fontsize=15)
plt.title('Space Launches By Country',fontsize=17)
plt.show()
Run Code Online (Sandbox Code Playgroud)
但是当使用折线图时,情节不是那么清楚 - Plot fig。
也无法根据值按降序对图例进行实体化和排序。
谁能帮我这个?