擅长:python、mysql、java
<p>看来你想要的Sr不,我有名单和口述包括在内。你知道吗</p>
<pre><code>y_10=[]
y_11=[]
with open("as.txt",'r') as f: # no need for f.close() when you use "with open" as the file is autonatically closed
lines = [x.split() for x in f.readlines()[2:]]
for line in lines:
if line[2].startswith("10"): # check if the 3rd element starts with "10"
y_10.append(line) # if so add to year 10 list
else:
y_11.append(line) # else it starts with "11" so add to year eleven list
print y_10,y_11
[['3.', 'Abc', '1010101', '9.1', '2014']] [['1.', 'XYZ', '1101111', '7.1', '2014'], ['2.', 'ZYX', '1101113', '8.2', '2014']]
# make dicts using zip, where the first element of each list is the key and the rest are the values
y_10_dict = dict(zip([x[0] for x in y_10], [y[1:] for y in y_10])) #
y_11_dict = dict(zip([x[0] for x in y_11], [y[1:] for y in y_11]))
print y_10_dict,y_11_dict
{'3.': ['Abc', '1010101', '9.1', '2014']} {'2.': ['ZYX', '1101113', '8.2', '2014'], '1.': ['XYZ', '1101111', '7.1', '2014']}
</code></pre>