擅长:python、mysql、java
<p>使用<a href="https://docs.python.org/3.6/library/collections.html?highlight=defaultdict#collections.defaultdict" rel="nofollow noreferrer"><strong><em>collections.defaultdict</em></strong></a>子类的解决方案:</p>
<pre><code>l = [('FRG', 'MCO TPA PIE SRQ', 'WAVEY EMJAY J174 SWL CEBEE '),
(' ', 'FMY RSW APF', 'WETRO DIW AR22 JORAY HILEY4'),
(' ', 'FMY RSW APF', 'WETRO DIW AR22 JORAY HILEY4'),
('FRG2', 'MCO TPA PIE SRQ', 'WAVEY EMJAY J174 SWL CEBEE '),
(' ', 'FMY RSW APF', 'WETRO DIW AR22 JORAY HILEY4')]
d = collections.defaultdict(list)
k = ''
for t in l:
if t[0].strip(): # if the 1st value of a tuple is not empty
k = t[0] # capturing dict key
if k:
d[k].append(t[1])
d[k].append(t[2])
print(dict(d))
</code></pre>
<p>输出:</p>
^{pr2}$