擅长:python、mysql、java
<p>您可以使用三种直接的列表理解:</p>
<pre><code>lst = ["aus-airport-1","aus-airport-2","us-airport-1","us-airport-2","aus-ship-1","us-ship-99","nz-airport-1"]
splits = list(map(lambda x: x.split('-'), lst))
lst1 = [x for x in splits if x[1] == 'airport' and x[0] != 'nz']
print(f'All airports excluding nz: {lst1}')
lst2 = [x for x in splits if x[1] == 'airport' and x[0] == 'aus']
print(f'All airports in aus: {lst2}')
lst3 = [x for x in splits if x[1] == 'ship']
print(f'All ships: {lst3}')
</code></pre>