Best optimal algorithm to compare zip tuples | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

Best optimal algorithm to compare zip tuples

Hello everyone, The problem is I want to compare 2 tuples : considering name1,name2,amount1,amount2,status1, status2, to be lists (Note that i have to use zips because a specific amount is linked to a name so you can't just compare one list and another list you have to compare either one list and use the index number to check the 2 other lists) or you may use several loops to check the comparaison. project1=zip(name1,amount1,status1) project2=zip(name2,amount2,status2) how would i make a program to check everypossibility? if names,amount,status are correct return "OK" , if something is missing i have to say in which projet and what is missing ? I'm working with python Thank you for your help guys If you want to see my program you can DM me i will send it to you. but with all these info you should be able to help me anyways. If can't help me please consider giving a thumbs up so others can see my post.

26th Mar 2021, 8:45 AM
Maximilien
Maximilien  - avatar
5 Antworten
+ 2
Tuples are compared position by position and strings are compared lexicographically. https://docs.python.org/3/reference/expressions.html#value-comparisons So you can use == to compare (in a nested loop) or use "in" with a single loop. Your names should reflect if a variable is a list (use plural, i.e. "names1" or append "_list", i.e. "name_list1"). For one direction you can do like this def missing(list1, list2): for el in list1: if el not in list2: yield el For the other direction just reverse. You could also copy list2, remove matches from that, append unmatched tuples to another and return the two lists. And perhaps python has a readymade function for this, which should always be preferred
26th Mar 2021, 10:22 AM
Benjamin J├╝rgens
Benjamin J├╝rgens - avatar
+ 2
Can you provide just a bit of example for name, amount and status? also what qualification is to pass to get an "OK"? I'm not sure what you are trying to do here. DM isn't working for me now, so I just wait for your response here, even if I can't help you further.
26th Mar 2021, 10:19 AM
Ipang
+ 2
I hope I made the right interpretation and assumptions, an example with expected output would be good
26th Mar 2021, 10:29 AM
Benjamin J├╝rgens
Benjamin J├╝rgens - avatar
0
Thank you for a lot for your help!
26th Mar 2021, 9:57 PM
Maximilien
Maximilien  - avatar
0
Your explanation helped me a lot!
26th Mar 2021, 9:58 PM
Maximilien
Maximilien  - avatar