-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"

4
  • 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" Commented Apr 5, 2022 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. Commented Apr 5, 2022 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 Commented Apr 5, 2022 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! stackoverflow.com/questions/6105777/… Commented Apr 6, 2022 at 1:55

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

3 Comments

leave a comment with more information and I'll edit this solution accordingly
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.
Ok I get you now. I've updated the post to fit your question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.