LoginSignup
0

More than 1 year has passed since last update.

posted at

updated at

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

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株式会社"']

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
What you can do with signing up
0