【python基础】Python中list列表的赋值方法及遇到问题处理

前言

调试lisa2coco的代码大时候,列表赋值之后为空。

code

>>> a=['go', 'stop', 'stopLeft', 'goLeft', 'warningLeft', 'warning', 'goForward']
>>> type(a)
<class 'list'>
>>> a.sort()
>>> a
['go', 'goForward', 'goLeft', 'stop', 'stopLeft', 'warning', 'warningLeft']
>>> b=a.sort()
>>> b

# 正确做法
>>> b=a
>>> b
['go', 'goForward', 'goLeft', 'stop', 'stopLeft', 'warning', 'warningLeft']

错误代码

tags = df['Annotation tag'].unique().tolist().sort()

正确做法

names = df['Annotation tag'].unique()
names.sort()
tags = names

 

参考

1. Python中list列表的赋值方法及遇到问题处理

2. python列表的sort()函数不可赋值给新列表

posted on 2022-06-16 19:36  鹅要长大  阅读(535)  评论(0编辑  收藏  举报

导航