Here's one way to do it:

import json

# Read the file
with open('file.txt', 'r') as f:
    content = f.read()

# Parse the JSON content into a dictionary
data = json.loads(content)

# Extract the rows
rows = data['rows']

# Create a new dictionary with aab004 as key and the row as value
result = {}
for row in rows:
    result[row['aab004']] = row

# Sort the dictionary by aab119
sorted_result = dict(sorted(result.items(), key=lambda x: x[1]['aab119']))

# Print the sorted dictionary
print(sorted_result)

This code reads the content of the file, parses it into a dictionary using json.loads(), extracts the rows, and creates a new dictionary with aab004 as the key and the row as the value. Then it sorts the dictionary by aab119 using sorted() and the key parameter, and finally prints the sorted dictionary.

use pythonread a txt file save the content as a dictand output aab004 sort by aab119txt file contentrowsaab004廉江市横山镇公共服务中心aab0191aab11931aae0361681200000000bab30115bfe3012311266150001bfe3a4人力资源和社会保障服

原文地址: https://www.cveoy.top/t/topic/bVV9 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录