<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def compare_orderings(info_frags_records, linkage_orderings):
 """Given linkage groups and info_frags records, link pseudo-chromosomes to scaffolds based on the initial contig composition of each group. Because info_frags records are usually richer and may contain contigs not found in linkage groups, those extra sequences are discarded. Example with two linkage groups and two chromosomes: (3, 'linkage_group_1', {'sctg_558': 'sctg_207'}) (2, 'linkage_group_2', {'sctg_994': 'sctg_842'}) """


    scaffolds = info_frags_records.keys()
    linkage_groups = linkage_orderings.keys()

    best_matching_table = dict()

    for scaffold, linkage_group in itertools.product(
        scaffolds, linkage_groups
    ):
        lg_ordering = [
            init_contig
            for init_contig, _ in itertools.groupby(
                linkage_orderings[linkage_group], operator.itemgetter(0)
            )
        ]
        scaffold_ordering = [
            init_contig
            for init_contig, bin_group in itertools.groupby(
                info_frags_records[scaffold], operator.itemgetter(0)
            )
            if init_contig in lg_ordering
        ]

        overlap = set(lg_ordering).intersection(set(scaffold_ordering))
        missing_locations = dict()
        for missing_block in sorted(set(lg_ordering) - set(overlap)):
            for i, init_contig in enumerate(lg_ordering):
                if init_contig == missing_block:
                    try:
                        block_before = lg_ordering[i - 1]
                    except IndexError:
                        block_before = "beginning"
                    missing_locations[missing_block] = block_before

        try:
            if len(overlap) > best_matching_table[scaffold][0]:
                best_matching_table[scaffold] = (
                    len(overlap),
                    linkage_group,
                    missing_locations,
                )

        except KeyError:
            best_matching_table[scaffold] = (
                len(overlap),
                linkage_group,
                missing_locations,
            )

    return best_matching_table