# 蟒蛇 |拆分真值和假值索引

| | | | |

` # Python3 代碼演示它是如何工作的 `
` # 分離 True 和 False 索引 `
` # 使用循環 `

` # 初始化列表 `

` test_list ` ` = ` ` [` ` False ` ` , ` ` True ` `, ` ` False ` `, ` ` 假 ` `, ` ` True ` `, ` ` True ` `] `

` `
` # 打印原始列表 `

` print ` ` (` `" 原來的列表是："` ` + ` ` str ` ` (test_list) ) `

` # True 和 False 值的單獨索引 ‚Äã‚Äã`
` # 使用循環 `

` res_true, res_false ` ` = ` ` [], [] `

` for ` ` i ` ` in ` ` range ` ` (` ` 0 ` `, ` ` len ` ` (test_list)): `

` ` ` i f ` ` test_list [i]: `

` res_true.append (i) `

` else ` `: `

` res_false.append (i ) `

` `
` # 打印結果 `

` print ` ` (` ` "分組後的真實索引：" ` ` + ` ` str ` ` (res_true)) `

` print ` ` (` ` "分組後的錯誤索引：" ` ` + ` ` str ` ` (res_false)) `

`原始列表為：[False, True, False, False, True, True] True in分組後的骰子：[1, 4 , 5] 分組後的錯誤索引：[0, 2, 3] `

` # Python3 代碼來演示它是如何工作的 `
` # 分開True 和 False 值的索引 ‚Äã‚Äã`
` # using loop + enumerate () `

` # 初始化列表 `

` test_list ` ` = ` ` [` ` False ` `, ` ` True ` `, ` ` False ` `, ` ` False ` `, ` ` True ` `, ` ` True ` ]

` #打印原始列表`

` print ` ` (` ` "原來的列表是：" ` ` + ` ` str ` ` (test_list)) `

` `
` # True 和 False 值的單獨索引 ‚Äã‚Äã`
` # 使用循環 + enumerate () `

` res_true, res_false ` ` = ` ` [], [] `

` for ` ` i, ele ` ` in ` ` enumerate ` ` (test_list): `

` ` ` temp ` ` = res_true if ele else res_false `

` temp.append (i) `

` # 打印結果 `

` print ( "分組後的真實索引：" + str (res_true)) `

` print ( "分組後的錯誤索引：" + str (res_false)) `

`原來的列表是： [False, True, False, False, True, True] 分組後的真實索引： [1, 4, 5] 分組後的錯誤索引：[0, 2, 3] `

## Shop

Learn programming in R: courses

\$

Best Python online courses for 2022

\$

Best laptop for Fortnite

\$

Best laptop for Excel

\$

Best laptop for Solidworks

\$

Best laptop for Roblox

\$

Best computer for crypto mining

\$

Best laptop for Sims 4

\$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

NUMPYNUMPY

How to convert Nonetype to int or string?

NUMPYNUMPY

How to specify multiple return types using type-hints

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

## Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method