open Printf let process_input init_size = let table = Hashtbl.create init_size and split line = match Str.split (Str.regexp_string "\t") line with | [a; b] -> (b, a) | _ -> failwith "Bad file format" in let rec loop() = let line = read_line() in let b, a = split line in (Hashtbl.add table b a; loop()) in try loop() with | End_of_file -> table let get_keys t = let module S = Set.Make (struct type t = string let compare = compare end) in S.elements(Hashtbl.fold (fun k d l -> S.add k l) t S.empty) let print table = let keys = List.sort compare (get_keys table) in List.iter (fun b -> printf "%s" b; let l = List.sort compare (Hashtbl.find_all table b) in List.iter (fun s -> printf "\t%s" s) l; print_newline() ) keys let () = print(process_input 2000)