<jupyter_start><jupyter_text>【python 入門】配列（list、tuple）をマスターする！  1.配列について知る  -変数と配列の違い<jupyter_code># 変数
a = 1
print('変数', a)

# 配列
list_a = [1,2,3]
print('配列', list_a)<jupyter_output>変数 1
配列 [1, 2, 3]<jupyter_text>-配列の種類<jupyter_code>list_a = [1,2,3]
print('list', list_a)

tuple_a = (1,2,3)
print('tuple', tuple_a)<jupyter_output>list [1, 2, 3]
tuple (1, 2, 3)<jupyter_text>2.データ取り出す  - 1つ取り出す<jupyter_code>list_a = [1, 2, 3, 4, 5]
print(list_a[1])<jupyter_output>2<jupyter_text>- 複数取り出す<jupyter_code>list_a = [1, 2, 3, 4, 5]
print(list_a[1:3])<jupyter_output>[2, 3]<jupyter_text>- マイナス値を使う<jupyter_code>list_a = [1, 2, 3, 4, 5]
print(list_a[-2])<jupyter_output>4<jupyter_text>- 変数に分けて取り出す<jupyter_code>list_a = [1, 2, 3]
a, b, c = list_a

print(a, b, c)
list_a = [1, 2, 3]
a, _, c = list_a

print(a, c)<jupyter_output>1 3<jupyter_text>3.list,tupleの相互変換<jupyter_code>list_a = [1, 2, 3, 4, 5]
tuple_a = tuple(list_a)
print(type(tuple_a), tuple_a)<jupyter_output><class 'tuple'> (1, 2, 3, 4, 5)<jupyter_text>4.配列にはいるもの<jupyter_code># 関数
def bmi(data):
    tall = data[0]/100
    weight = data[1]
    return weight/(tall*tall)
# list
tall_weight = [170, 70]
# 文字列 & list & 関数 を入れる
list_various = ['Aさん', tall_weight, bmi]

# データ確認
print(list_various)

# リストから取り出して使う
print(list_various[0], list_various[2](list_various[1]))<jupyter_output>['Aさん', [170, 70], <function bmi at 0x0000021DCA033F78>]
Aさん 24.221453287197235<jupyter_text>5.追加、結合する  - append<jupyter_code>list_a = [1, 2, 3]
list_b = [4, 5]
list_a.append(list_b)
print(list_a)<jupyter_output>[1, 2, 3, [4, 5]]<jupyter_text>- insert<jupyter_code>list_a = [1, 2, 3]
list_b = [4, 5]
list_a.insert(1, list_b)
print(list_a)<jupyter_output>[1, [4, 5], 2, 3]<jupyter_text>- extend<jupyter_code>list_a = [1, 2, 3]
list_b = [4, 5]
list_a.extend(list_b)
print(list_a)
list_a = [1, 2, 3]
list_b = [4, 5]
list_a = list_a + list_b
print(list_a)<jupyter_output>[1, 2, 3, 4, 5]<jupyter_text>6.削除、初期化する  - clear<jupyter_code># 削除前
list_a = [1, 2, 3, 4, 5]
print(list_a)
# 削除後
list_a.clear()
print(list_a)
list_a = []<jupyter_output><empty_output><jupyter_text>- pop<jupyter_code>list_a = [1, 2, 3, 4, 5]
print(list_a)

# 1つ取り出す
a = list_a.pop()
print(a, list_a)

# また、1つ取り出す
a = list_a.pop()
print(a, list_a)<jupyter_output>[1, 2, 3, 4, 5]
5 [1, 2, 3, 4]
4 [1, 2, 3]<jupyter_text>- remove<jupyter_code>list_a = [1, 2, 3, 4, 5]
print(list_a)

# 2を削除
list_a.remove(2)
print(list_a)
list_a = ['a', 'b', 'c']
print(list_a)

# a削除
list_a.remove('a')
print(list_a)<jupyter_output>['a', 'b', 'c']
['b', 'c']<jupyter_text>7. 2次元配列<jupyter_code># 2次元目のデータ
list_1_1 = [1,2]
list_1_2 = [3,4]
list_1_3 = [5,6]
list_a = [list_1_1, list_1_2, list_1_3]
print(list_a)

# 1次元目の2つ目を取得
print(list_a[1])
# 2次元目のデータ
list_a = [[1, 2], 
          [3, 4], 
          [5, 6]]
print(list_a)

# 1次元目の2つ目を取得
print(list_a[1])<jupyter_output>[[1, 2], [3, 4], [5, 6]]
[3, 4]<jupyter_text>8. 並び替え<jupyter_code>list_a = [3, 4, 5, 1, 2]

# 昇順
list_a.sort(reverse=True)
print(list_a)

# 降順
list_a.sort(reverse=False)
print(list_a)<jupyter_output>[5, 4, 3, 2, 1]
[1, 2, 3, 4, 5]<jupyter_text>9. 検索  - in<jupyter_code># 数値
list_a = [1, 2, 3]
print('1含む？', 1 in list_a)
print('10含む？', 10 in list_a)

# 文字列
list_a = ['a', 'b', 'c']
print('a含む？', 'a' in list_a)
print('d含む？', 'd' in list_a)
list_a = ['a', 'b', 'c']
if 'a' in list_a:
    print('aを含む')
else:
    print('aを含まない')<jupyter_output>aを含む<jupyter_text>- index<jupyter_code>list_a = ['a', 'b', 'c']
#　データ含む
ind = list_a.index('b')
print('bの場所', ind)

# データ含まない >> エラー
ind = list_a.index('d')<jupyter_output>bの場所 1<jupyter_text>10. 計算<jupyter_code>import statistics
list_a = [1,2,3,4,5]
print('合計', sum(list_a))
print('最大', max(list_a))
print('最小', min(list_a))
print('中央', statistics.median(list_a))
print('平均', statistics.mean(list_a))
print('標本標準偏差', statistics.stdev(list_a))<jupyter_output>合計 15
最大 5
最小 1
中央 3
平均 3
標本標準偏差 1.5811388300841898
{'fraction_non_alphanumeric': 0.20107581967213115, 'fraction_numerical': 0.07274590163934426, 'mean_word_length': 6.010771992818672, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '19', 'dir': 'jupyter-structured-clean-dedup', 'id': '525279', 'license': 'MIT', 'n_tokens_mistral': 2390, 'n_tokens_neox': 2246, 'n_words': 376, 'path': 'array/array.ipynb', 'repo_name': 'hituji1012/python', 'size': '3904'}