<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def collapse_degenerate_markers(linkage_records):
 """Group all markers with no genetic distance as distinct features to generate a BED file with. Simple example with sixteen degenerate markers: 16 5 The degenerate features (identical linkage group, genetic distance and original scaffold) are collapsed into a region: [1, 31842, 94039, 207] The format is [linkage group, start, end, original scaffold]. If a singleton (non-degenerate) feature is found, the region is simply a single point in the genome: [1, 116303, 116303, 207] so 'start' and 'end' are identical. Two markers are not considered degenerate if they belong to different original scaffolds, even if they are in terms of genetic linkage: [1, 158925, 258658, 207] [[1, 41893, 41893, 486], [1, 36614, 50582, 516]] """


    def degeneracy(linkage_record):
        linkage_group, genetic_distance, scaffold = (
            linkage_record[1],
            linkage_record[2],
            linkage_record[3],
        )
        return (linkage_group, genetic_distance, scaffold)

    degenerate_records = []
    for _, degenerate_group in itertools.groupby(
        linkage_records, key=degeneracy
    ):
        group_list = list(degenerate_group)
        start_record, end_record = group_list[0], group_list[-1]

        assert (start_record[1], start_record[2], start_record[3]) == (
            end_record[1],
            end_record[2],
            end_record[3],
        )

        start_position = start_record[-1]
        end_position = end_record[-1]

        scaffold = start_record[3]
        linkage_group = start_record[1]
        record = [linkage_group, start_position, end_position, scaffold]

        degenerate_records.append(record)

    return degenerate_records