我在一個位字串中找到 1,然后將它們存盤起來。
樣本資料:

示例代碼:
def indices(chromosome):
return {i for i,c in enumerate(chromosome) if c=='1'}
for ind in df_initial_pop['initial_pop'].index:
locations = indices(df_initial_pop['initial_pop'] [ind])
print (locations)
輸出:
{32, 29, 31}
{8, 34, 23}
{34, 35, 31}
{17, 14, 31}
{26, 19, 34}
現在,我想訪問32, 29, and 31它們中的每一個并將它們存盤在一個單獨的變數中。可能嗎?
uj5u.com熱心網友回復:
當然可以,但是使用單個變數意味著您的集合中的元素數量是固定的。
s = {32, 29, 31}
a,b,c = s
# Now a=32, b=29, c=31
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/519473.html
