0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

リスト内包表記が苦手すぎたのでメモ

Posted at

###まずは通常のリスト作成
list_1 = [] for i in range(10):     list_1.append(i) list_1

リスト内包表記 simple

list_2 = [i for i in range(10)] list_2

文字列リストver

countries = np.array(['France','Japan','USA','Russia','USA','Mexico','Japan']) list_3 = [country for country in countries] list_3

文字列リストver(重複削除のおまけつき)

list_4 = [country for country in np.unique(countries)] list_4

if文ありver

list_5= [i for i in range(10) if i % 2 == 0] list_5

if elseありver

list_6= [i if i%2 == 0 else "奇数" for i in range(10)] list_6

if else orありver(世界のなべあつ風)

list_7 = ["サン" if i%3 ==0 or str(i)[-1] == '3' else i for i in range(1,101)] list_7

0
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
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?