LoginSignup
1
0

More than 1 year has passed since last update.

Python3 List型の内容をsort uniqしたい

Last updated at Posted at 2022-03-17

List型の内容をsort uniqしたい場合は、listをsetしてsortedすると実現できる。

list = sorted(set(list))

サンプルコード

# サンプルListを作成
company_list = ['"テスト3株式会社"', '"テスト3株式会社"', '"テスト1株式会社"', '"テスト2株式会社"', '"テスト3株式会社"']

# 中身確認
print(company_list)
['"テスト3株式会社"', '"テスト3株式会社"', '"テスト1株式会社"', '"テスト2株式会社"', '"テスト3株式会社"']

# Listのsort uniqをする
company_list = sorted(set(company_list))

# 重複が削除されソートされる
print(company_list)
['"テスト1株式会社"', '"テスト2株式会社"', '"テスト3株式会社"']
1
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0