Python ma'lumotlar ro'yxatida tartiblangan

Bizda uchta turli varaqalar mavjud:

1th = [(442, 248), (442, 249), (442, 250), (442, 251), (442, 252), (442, 253), (442, 254), (442, 255), (442, 256), (442, 257), (442, 258), (442, 259), (442, 260), (442, 261)]
2nd = [(96, 128, 144), (112, 128, 144), (80, 96, 96), (32, 48, 48), (64, 64, 64), (64, 64, 64), (32, 32, 32), (16, 16, 0), (16, 16, 0), (16, 16, 0), (16, 16, 0), (16, 16, 16), (32, 32, 32)]
3-rd = [(16, 16, 16), (32, 32, 32)]

Dastur 3-ro'yxatdan (" Etalon " deb nomlang) qiymati baholang, uni ikkinchi soniya bilan taqqoslang va agar u indeks bilan 2 qiymatini qabul qilsa va olingan bo'lsa qiymat dasturi Etalondan keyin 3-ro'yxatga kiritilishi kerak.

Natijada shunday bo'lishi kerak:

[((16, 16, 16), (442, 255), (442, 256), (442, 257), (442, 258)), ((32, 32, 32),(442, 248), (442, 249), (442, 250))]

Yuqoridagi barcha ma'lumotlar RGB ranglar, xy koordinatalari va piksellarni rangi saralash uchun talab qilinadi.

Savol: qaysi indikatorga ega bo'lgan elementni uchinchi ro'yxatga qo'shish uchun qanday usul ishlatilishi kerak? Quyidagilarni sinab ko'rdim, lekin u ishlamayapti:

3-rd.append(1th[index from 2nd])
2
Bu mumkin bo'lgan misollar bo'lsa-da, 1th , 2nd va 3-rd Python da o'zgaruvchining nomlari haqiqiy emas. Yoki ingliz tilida bu masalada.
qo'shib qo'ydi muallif Christian König, manba
Bu mumkin bo'lgan misollar bo'lsa-da, 1th , 2nd va 3-rd Python da o'zgaruvchining nomlari haqiqiy emas. Yoki ingliz tilida bu masalada.
qo'shib qo'ydi muallif Christian König, manba
Bu mumkin bo'lgan misollar bo'lsa-da, 1th , 2nd va 3-rd Python da o'zgaruvchining nomlari haqiqiy emas. Yoki ingliz tilida bu masalada.
qo'shib qo'ydi muallif Christian König, manba
"kerak bo'lganda ishlamaydi" ... Siz olgan har qanday xatolarni yoki noto'g'ri chop etishni bera olasizmi?
qo'shib qo'ydi muallif jojonas, manba
3-rdappend (1-chi ikkinchi indeks) [[16, 16, 16], 32, 32, 32, 442, 248), 442, 249, 442, 250 RGB, XY, XY, XY, RGB XY, XY, XY] [RGB, XY, XY, XY], [442,252]
qo'shib qo'ydi muallif Alek Szczęsnowicz, manba
3-rdappend (1-chi ikkinchi indeks) [[16, 16, 16], 32, 32, 32, 442, 248), 442, 249, 442, 250 RGB, XY, XY, XY, RGB XY, XY, XY] [RGB, XY, XY, XY], [442,252]
qo'shib qo'ydi muallif Alek Szczęsnowicz, manba
1-chi, 2-chi, 3-chi o'qishni "birinchi piton ro'yxati", "ikkinchi" va hk
qo'shib qo'ydi muallif Alek Szczęsnowicz, manba
1-chi, 2-chi, 3-chi o'qishni "birinchi piton ro'yxati", "ikkinchi" va hk
qo'shib qo'ydi muallif Alek Szczęsnowicz, manba

6 javoblar

Quyidagilarni tekshirib ko'ring:

first = [(442, 248), (442, 249), (442, 250), (442, 251), (442, 252), (442, 253), (442, 254), (442, 255), (442, 256), (442, 257), (442, 258), (442, 259), (442, 260), (442, 261)]
second = [(96, 128, 144), (112, 128, 144), (80, 96, 96), (32, 48, 48), (64, 64, 64), (64, 64, 64), (32, 32, 32), (16, 16, 16), (16, 16, 16), (16, 16, 16), (16, 16, 0), (16, 16, 16), (32, 32, 32)]
third = [(16, 16, 16), (32, 32, 32)]            

output = []

for v3 in third:
    f = True
    run = []
    for i2, v2 in enumerate(second):
        if v3 == v2:
            if f:
                run.append(v3)
                f = False

            run.append(first[i2])

    if run:
        output.append(run)

print output            

Bu mahsulotni ishlab chiqaradi:

[[(16, 16, 16), (442, 255), (442, 256), (442, 257), (442, 259)], [(32, 32, 32), (442, 254), (442, 260)]]    
0
qo'shib qo'ydi
to'liq menga kerak! katta rahmat!
qo'shib qo'ydi muallif Alek Szczęsnowicz, manba

Quyidagilarni tekshirib ko'ring:

first = [(442, 248), (442, 249), (442, 250), (442, 251), (442, 252), (442, 253), (442, 254), (442, 255), (442, 256), (442, 257), (442, 258), (442, 259), (442, 260), (442, 261)]
second = [(96, 128, 144), (112, 128, 144), (80, 96, 96), (32, 48, 48), (64, 64, 64), (64, 64, 64), (32, 32, 32), (16, 16, 16), (16, 16, 16), (16, 16, 16), (16, 16, 0), (16, 16, 16), (32, 32, 32)]
third = [(16, 16, 16), (32, 32, 32)]            

output = []

for v3 in third:
    f = True
    run = []
    for i2, v2 in enumerate(second):
        if v3 == v2:
            if f:
                run.append(v3)
                f = False

            run.append(first[i2])

    if run:
        output.append(run)

print output            

Bu mahsulotni ishlab chiqaradi:

[[(16, 16, 16), (442, 255), (442, 256), (442, 257), (442, 259)], [(32, 32, 32), (442, 254), (442, 260)]]    
0
qo'shib qo'ydi
to'liq menga kerak! katta rahmat!
qo'shib qo'ydi muallif Alek Szczęsnowicz, manba

Quyidagilarni tekshirib ko'ring:

first = [(442, 248), (442, 249), (442, 250), (442, 251), (442, 252), (442, 253), (442, 254), (442, 255), (442, 256), (442, 257), (442, 258), (442, 259), (442, 260), (442, 261)]
second = [(96, 128, 144), (112, 128, 144), (80, 96, 96), (32, 48, 48), (64, 64, 64), (64, 64, 64), (32, 32, 32), (16, 16, 16), (16, 16, 16), (16, 16, 16), (16, 16, 0), (16, 16, 16), (32, 32, 32)]
third = [(16, 16, 16), (32, 32, 32)]            

output = []

for v3 in third:
    f = True
    run = []
    for i2, v2 in enumerate(second):
        if v3 == v2:
            if f:
                run.append(v3)
                f = False

            run.append(first[i2])

    if run:
        output.append(run)

print output            

Bu mahsulotni ishlab chiqaradi:

[[(16, 16, 16), (442, 255), (442, 256), (442, 257), (442, 259)], [(32, 32, 32), (442, 254), (442, 260)]]    
0
qo'shib qo'ydi
to'liq menga kerak! katta rahmat!
qo'shib qo'ydi muallif Alek Szczęsnowicz, manba
import pandas as pd
first = pd.Series([(442, 248), (442, 249), (442, 250), (442, 251), (442, 252), (442, 253), (442, 254), (442, 255), (442, 256), (442, 257), (442, 258), (442, 259), (442, 260), (442, 261)])
second = pd.Series([(96, 128, 144), (112, 128, 144), (80, 96, 96), (32, 48, 48), (64, 64, 64), (64, 64, 64), (32, 32, 32), (16, 16, 16), (16, 16, 16), (16, 16, 16), (16, 16, 0), (16, 16, 16), (32, 32, 32)])

third = [(16, 16, 16), (32, 32, 32)] 

res = [ [item] + first[ second[ second == item].index ].tolist() for item in third]

[[(16, 16, 16), (442, 255), (442, 256), (442, 257), (442, 259)], [(32, 32, 32), (442, 254), (442, 260)]]
0
qo'shib qo'ydi

Pythonda elementni ro'yxatdagi muayyan indeksga kiritish imkonini beruvchi insert() usuli bor.

list_name = ["a", "b", "d"]

list_name.insert(2,"d")

print list_name

#prints ['a', 'b', 'd', 'd']
0
qo'shib qo'ydi

Pythonda elementni ro'yxatdagi muayyan indeksga kiritish imkonini beruvchi insert() usuli bor.

list_name = ["a", "b", "d"]

list_name.insert(2,"d")

print list_name

#prints ['a', 'b', 'd', 'd']
0
qo'shib qo'ydi
Python
Python
372 ishtirokchilar

Bu guruh python dasturlash tilini muhokama qilish uchun. Iltimos, o'zingizni hurmat qiling va faqat dasturlash bo'yicha yozing. Botlar mavzusini @botlarhaqida guruhida muhokama qling! FAQ: @PyFAQ Offtopic: @python_uz_offtopic

Python offtopic group !
Python offtopic group !
150 ishtirokchilar

@python_uz gruppasining offtop gruppasi. offtop bo'lsa ham reklama mumkin emas ) Boshqa dasturlash tiliga oid gruppalar @languages_programming