第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何選擇列表中的項目?

如何選擇列表中的項目?

肥皂起泡泡 2021-09-02 20:20:39
我有:我有兩個這樣的列表:[('ELON_MUSK', True), ('BARACK_OBAMA', False), ('DONALD_TRUMP', False)][('ELON_MUSK', False), ('BARACK_OBAMA', True), ('DONALD_TRUMP', False)]我想(問題):由于ELON_MUSK和BARACK_OBAMA是true我想給他們,并追加檢索到的字符串,但我敢肯定,我不知道如何尋找的問題,正確的方面,因為我什么也沒有發(fā)現(xiàn)這一點,因此要求在這里。我希望發(fā)生:People in this image: ELON_MUSK BARACK_OBAMA我正在做:for imagePath in imageArray:        # Try comparing an unknown image        unknown_image = face_recognition.load_image_file(imagePath)        unknown_face = face_recognition.face_encodings(unknown_image)        face_count = len(unknown_face)        name_list = ""        print("Checking: " + imagePath)        print("----------------------------")        for i in range(face_count):                result = face_recognition.compare_faces(face_encodings, unknown_face[i])                # Print the result as a list of names with True/False                names_with_result = list(zip(face_names, result))                print(names_with_result, end = '')                print(" -- Checking face #" + str(i+1))                # vvv I HAVE NO IDEA ABOUT THIS PART vvv                if "True" in names_with_result:                        #name_list = name_list + " name of the TRUE person";        print("People in this image: " + name_list)我越來越:People in this image: 
查看完整描述

3 回答

?
慕斯709654

TA貢獻1840條經(jīng)驗 獲得超5個贊

# Separate lists of (name, is_in_image) tuples

>>> a = [('ELON_MUSK', True), ('BARACK_OBAMA', False), ('DONALD_TRUMP', False)]

>>> b = [('ELON_MUSK', False), ('BARACK_OBAMA', True), ('DONALD_TRUMP', False)]

# Combine the lists

>>> together = a + b

# Create a list containing all names if the second element (is_in_image) is True

>>> [name for name, is_in_image in together if is_in_image]

['ELON_MUSK', 'BARACK_OBAMA']

>>> print('People in this image: {}'.format(', '.join([name for name, is_in_image in together if is_in_image])))

People in this image: ELON_MUSK, BARACK_OBAMA

我認為你目前的做法主要的問題是,你的追加試驗if 'True' in names_with_result,而不是if True in names_with_result... 'True' != True...


>>> sample_result = ('ELON_MUSK', True)

>>> 'True' in sample_result

False

>>> True in sample_result

True

第一個測試'True' in sample_result返回 False,然后不會觸發(fā)您的附加邏輯,從而傳遞該元素。


查看完整回答
反對 回復(fù) 2021-09-02
?
慕的地10843

TA貢獻1785條經(jīng)驗 獲得超8個贊

你也可以這樣做:


l1 = [('ELON_MUSK', True), ('BARACK_OBAMA', False), ('DONALD_TRUMP', False)]

l2 = [('ELON_MUSK', False), ('BARACK_OBAMA', True), ('DONALD_TRUMP', False)]


# join the two list

l1.extend(l2)


# create a simple function that return a list of true


f = lambda x: [i for i,j in x if j]


print('{} is not {}'.format(*f(l1)))


查看完整回答
反對 回復(fù) 2021-09-02
?
人到中年有點甜

TA貢獻1895條經(jīng)驗 獲得超7個贊

試試這個:


A= [('ELON_MUSK', True), ('BARACK_OBAMA', False), ('DONALD_TRUMP', False)]

B= [('ELON_MUSK', False), ('BARACK_OBAMA', True), ('DONALD_TRUMP', False)]



name_list  = ''.join([a[0]+' , '+b[0] for a in A for b in B if a[1]==True and b[1]== True])

print("People in this image: "+ name_list)


查看完整回答
反對 回復(fù) 2021-09-02
  • 3 回答
  • 0 關(guān)注
  • 211 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號