skip to Main Content

I’m encountering a problem, I’ve been trying for days but without getting any results, I would like to compare 2 dictionaries, in one dictionary there are "Pre match" football matches and in the second dictionary there are "Live" football matches.

I would like to compare them with each other and if there are no pre-match games live you must print them, now I will show the code better

EXAMPLE 1

`import json

pre = [{
        "Sport": "Calcio",
        "Championship": "Italia - Serie A",
        "Home": "Genoa",
        "Away": "Inter",
        "Match Full": "Genoa v Inter",
        "URL": "https://www.bet365.it/#/AC/B1/C1/D8/E158355896/F3/I0/",
        "Start Data": "19 Lug",
        "Start Time": "21:30"
    },
    {
        "Sport": "Calcio",
        "Championship": "Italia - Serie A",
        "Home": "Parma",
        "Away": "Fiorentina",
        "Match Full": "Parma v Fiorentina",
        "URL": "https://www.bet365.it/#/AC/B1/C1/D8/E158355904/F3/I0/",
        "Start Data": "17 Ago",
        "Start Time": "18:30"
    }]

live = [{
        "Sport": "Calcio",
        "Championship": "Myanmar - Lega Nazionale",
        "Home": "Dagon Star United FC",
        "Away": "Ispe FC",
        "Match Full": "Dagon Star United FC v Ispe FC"
    },
    {
        "Sport": "Calcio",
        "Championship": "Italia - Serie A",
        "Home": "Genoa",
        "Away": "Inter",
        "Match Full": "Genoa v Inter"
    }]

check = [[x for x in pre if x['Match Full'] != i['Match Full']] for i in live]

print(check)`

I am not receiving the desired result, I also tried the following code, without receiving the right result

EXAMPLE 2

`import json

pre = [{
        "Sport": "Calcio",
        "Championship": "Italia - Serie A",
        "Home": "Genoa",
        "Away": "Inter",
        "Match Full": "Genoa v Inter",
        "URL": "https://www.bet365.it/#/AC/B1/C1/D8/E158355896/F3/I0/",
        "Start Data": "19 Lug",
        "Start Time": "21:30"
    },
    {
        "Sport": "Calcio",
        "Championship": "Italia - Serie A",
        "Home": "Parma",
        "Away": "Fiorentina",
        "Match Full": "Parma v Fiorentina",
        "URL": "https://www.bet365.it/#/AC/B1/C1/D8/E158355904/F3/I0/",
        "Start Data": "17 Ago",
        "Start Time": "18:30"
    }]

live = [{
        "Sport": "Calcio",
        "Championship": "Myanmar - Lega Nazionale",
        "Home": "Dagon Star United FC",
        "Away": "Ispe FC",
        "Match Full": "Dagon Star United FC v Ispe FC"
    },
    {
        "Sport": "Calcio",
        "Championship": "Italia - Serie A",
        "Home": "Genoa",
        "Away": "Inter",
        "Match Full": "Genoa v Inter"
    }]

for x in pre:
    for i in live:
        if x['Match Full'] != i['Match Full']:
            print(x['Match Full'])`

What I’m trying to get is only the missing pre-match in the "live" dict, in this case it should only print "Parma v Fiorentina" as it is missing in the dictionary

Any solution will be appreciated, thank you in advance.

print(x[‘Match Full’])

missing matches

2

Answers


  1. this should do

    def get_set(matches):
        return set([match_['Match Full'] for match_ in matches])
        
    pre_set= get_set(pre)
    live_set = get_set(live)
    print(pre_set-live_set) # {'Parma v Fiorentina'}
    
    Login or Signup to reply.
  2. #Create a list of value of 'Match Full' from live
    live_lst = [x["Match Full"] for x in live] 
    
    for x in pre:
        if x["Match Full"] not in live_lst:
            print(x["Match Full"])
    
    #Output : Parma v Fiorentina
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search