-1

Hi guys i just start to programming and im trying to get this right.

A = [['1','Jack','33'], ['2','Maria','23'], ['3','Christian','9'] ] 
B = [['1','Jack','33'], ['2','Maria','23'], ['3','Christian','9'], ['4','Denis','45'] ]

I want to check the array B[0] and print out just "4 Denis 45"

dumbPotato21
  • 5,669
  • 5
  • 21
  • 34
  • `B` is a list which contains another list. Get the first list by `B[0]` and then access whichever index you want from it - like `B[0][-1]` to get "4 Denis 45" – dumbPotato21 Apr 05 '22 at 21:30
  • What do you mean by "check `B[0]`"? Why do you want to print "4 Denis 45"? Because it's the last sublist? Because it's Denis? Because you like him better, or because he's not in the other list? Because he has the highest score? Your question is unclear, please clarify and explain what you tried and how it failed. – Thierry Lathuille Apr 05 '22 at 21:34
  • yes, it's the last one on the list but I actually want to take a very large list and compare it with the list that is already inside the DB. If and index 0 of list B is equal to index 0 of list A, I want it to skip that data and add only data from list B that doesn't exist in DB – Cícero Cunha Apr 05 '22 at 21:39
  • I believe this StackOverflow post will be helpful for you, it is about comparing lists of lists (what you have here). Keep learning, it only gets easier! https://stackoverflow.com/questions/6105777/how-to-compare-a-list-of-lists-sets-in-python – Joe Howard Apr 06 '22 at 01:55

1 Answers1

0

I'm unsure what of you want. Is this it:

A_ids = [item[0] for item in A]
for lst in B:
    if lst[0] not in A_ids:
        # You can do whatever you want to do with lst at this point
        print(" ".join(lst))

Output:

4 Denis 45
Emmanuel
  • 245
  • 2
  • 5
  • leave a comment with more information and I'll edit this solution accordingly – Emmanuel Apr 05 '22 at 21:37
  • I have a database with clients already added to it. I'm uploading an xls spreadsheet. spreadsheet some customers that are in the database and others that are not. I want to compare the two and only add new customers to the bank. I need to compare with index zero, which is the id of each customer. – Cícero Cunha Apr 05 '22 at 21:48
  • Ok I get you now. I've updated the post to fit your question. – Emmanuel Apr 06 '22 at 10:37