擅长:python、mysql、java
<p>您可以告诉我们以下理解:</p>
<pre><code>unfiltered = ['Cat,Dog,Cow', '', 'Horse,Whale', 'Fish,Giant Elephant']
wtc = {'Whale': 'Big Whale', 'Fish': 'Jellyfish'}
result = [','.join(wtc.get(s, s) for s in e.split(',')) for e in unfiltered]
# ['Cat,Dog,Cow', '', 'Horse,Big Whale', 'Jellyfish,Giant Elephant']
</code></pre>
<p>这利用了<a href="https://docs.python.org/2/library/stdtypes.html#dict.get" rel="nofollow noreferrer">^{<cd1>}</a>方法。您将<a href="https://docs.python.org/2/library/stdtypes.html#str.split" rel="nofollow noreferrer">^{<cd2>}</a>列表元素、应用转换和<a href="https://docs.python.org/2/library/stdtypes.html#str.join" rel="nofollow noreferrer">^{<cd3>}</a>标记重新组合在一起。你知道吗</p>