Ich habe eine Eingabe wie diese:
{"id": 123, "class": t1, "format": f1, "class-2": t1, ...}
{"id": 456, "class": t2, "format": f1, ...}
{"id": 567, "class": t1, "format": f2, "class-2": t2, "class-3": t1, ...}
...
Ich möchte eine Ausgabe wie diese:
123 = t1
456 = t2
567 = t1
...
(567 Klassifizierung vergleicht, wie oft t1 gegen t2 erscheint)
ich versuche Forschung aber ohne Erfolg. Es ist eine riesige Textdatei und ich habe alles in dieselbe Zeile gestellt, aber ich kann nicht richtig jedes Klassenauftritt zwischen jeder ID zählen, um es zu vergleichen.
Antworten:
0 für die Antwort № 1Ich bin nicht 100% sicher, dass ich verstehe, was Sie wollen, und da Sie keinen Code geschrieben haben, ist dies mein Versuch, Regex zu verwenden:
import re
string = """{"id": 123, "class": t1, "format": f1, "class-again": t1, ...}
{"id": 456, "class": t2, "format": f1, ...}
{"id": 567, "class": t1, "format": f2, "class-again": t2, "class-again": t1, ...} """
for id, cl in zip(re.findall(""id": (.+?),", string),
re.findall(""class": (.+?),", string)):
print("{} = {}".format(id, cl))
Ausgabe:
123 = t1
456 = t2
567 = t1