Python 文本文件中的并行排序数据

Python 文本文件中的并行排序数据,python,sorting,io,Python,Sorting,Io,我在一个文本文件中有以下数据 [Test id_g001,**Test id_g002,Test id_g000, Value_is_0, Value_is_2, Value_is_1] 我只能对数据进行排序。如何并行地对数据进行排序,以便按如下方式对数据进行排序?测试ID和值都需要排序 Test ID ---------------Value g000 ------------------- 0 g001 ------------------- 1 g002

我在一个文本文件中有以下数据

[Test id_g001,**Test id_g002,Test id_g000, Value_is_0, Value_is_2, Value_is_1]
我只能对数据进行排序。如何并行地对数据进行排序,以便按如下方式对数据进行排序?测试ID和值都需要排序

 Test ID ---------------Value        
 g000 ------------------- 0  
 g001  ------------------- 1  
 g002  ------------------- 2
代码是:

def readFile():
from queue import PriorityQueue
q = PriorityQueue()
#try block will execute if the text file is found
try:
    fileName= open("textFile.txt",'r')
    for line in fileName:
            for string in line.strip().split(','):
                q.put(string[-4:])
    fileName.close() #close the file after reading          
    print("Displaying Sorted Data")
    while not q.empty():
        print(q.get())
        #catch block will execute if no text file is found
except IOError:
            print("Error: FileNotFoundException")
            return

假设您有一个字符串列表,如下所示:

>>> l = ['Test id_g001','**Test id_g002','Test id_g000', 'Value_is_0', 'Value_is_2', 'Value_is_1']
您想根据ID和Value的值对它们进行排序,然后可以这样做:

>>> from operator import itemgetter
>>> sorted(l, key=itemgetter(-1))
['Test id_g000', 'Value_is_0', 'Test id_g001', 'Value_is_1', '**Test id_g002', 'Value_is_2']

您需要以元组列表的形式读入该文件,然后对第二项进行排序,这个问题已经在这里得到了回答,所以我不打算回答,捕捉
IOError
print(“Error:FileNotFoundException”)
。使用csv库读取您的csv文件我来自Java背景。这种语言对我来说相当陌生