code: def main():
      segments_dict = {}
      with codecs.open(args.segments, "r", encoding="utf-8") as f:
          for line in f:
              utt_id, spk, start, end = line.strip().split()
              segments_dict[utt_id] = (start, end)
  
      segments_spk = deque([])
      with codecs.open(args.segments, "r", encoding="utf-8") as f:
          spk_prev = None
          for line in f:
              utt_id, spk, start, end = line.strip().split()
              start = float(start) * 100  # per 10ms
              end = float(end) * 100  # per 10ms
              if spk_prev is not None and spk != spk_prev:
                  segments_dict = merge(segments_spk, segments_dict)
                  segments_spk = deque([])  # reset
              segments_spk.append(([utt_id], start, end))
              spk_prev = spk
  
      with codecs.open(
          args.output_segments, "w", encoding="utf-8"
      ) as f:
          for utt_id, (start, end) in sorted(
              segments_dict.items(), key=lambda x: x[0]
          ):
              spk = args.delimiter.join(
                  utt_id.split(args.delimiter)[:-2]
              )
              f.write("%s %s %s %s\n" % (utt_id, spk, start, end))
  
      spk2utt_dict = {}
      with codecs.open(args.output_utt2spk, "w", encoding="utf-8") as f:
          for utt_id, ref in sorted(
              segments_dict.items(), key=lambda x: x[0]
          ):
              spk = args.delimiter.join(
                  utt_id.split(args.delimiter)[:-2]
              )
              f.write("%s %s\n" % (utt_id, spk))
  
              if spk not in spk2utt_dict:
                  spk2utt_dict[spk] = [utt_id]
              else:
                  spk2utt_dict[spk] += [utt_id]
  
      with codecs.open(args.output_spk2utt, "w", encoding="utf-8") as f:
          for spk, utt_ids in sorted(
              spk2utt_dict.items(), key=lambda x: x[0]
          ):
              f.write("%s %s\n" % (spk, " ".join(utt_ids)))
  
imports: import argparse
  import codecs
  from collections import deque
label_desc: Use image node_id 2 for calling a global function with example usage: main() without return types