擅长:python、mysql、java
<p>在逗号处拆分字符串并使用列表:</p>
<pre><code>[int(el[2:]) for el in note_to.split(',') if el.startswith('e-')]
</code></pre>
<p>我假设您只想得到以<code>e-</code>开头的值;如果您想要不同的东西,您需要澄清您的问题。你知道吗</p>
<p>因为我们已经确定元素以<code>e-</code>开头,所以获取整数值就像跳过前2个字符一样简单。你知道吗</p>
<p>演示:</p>
<pre><code>>>> note_to = u'c-100001,e-100001,e-100011,e-100009'
>>> [int(el[2:]) for el in note_to.split(',') if el.startswith('e-')]
[100001, 100011, 100009]
</code></pre>
<p>如果您只想获得<em>唯一的</em>值,并且顺序无关紧要,请使用一个集合,并使用<code>str.rpartition()</code>分割起始字符串(可能超过2个字符,或者总共缺少):</p>
<pre><code>set(int(el.rpartition('-')[-1]) for el in note_to.split(','))
</code></pre>
<p>根据你的具体需要,你可以随时把它写回清单。你知道吗</p>
<p>演示:</p>
<pre><code>>>> set(int(el.rpartition('-')[-1]) for el in note_to.split(','))
set([100001, 100011, 100009])
>>> list(set(int(el.rpartition('-')[-1]) for el in note_to.split(',')))
[100001, 100011, 100009]
</code></pre>