擅长:python、mysql、java
<p>对于转发:</p>
<pre><code>[word[4*l:4*(l+1)] for l in range(0, int(len(word)/4)+1)]
['help', '_me_', 'code', '_ple', 'ase']
</code></pre>
<p>对于向后:</p>
<pre><code>[word[::-1][4*l:4*(l+1)][::-1] for l in range(0, int(len(word)/4)+1)]
['ease', 'e_pl', '_cod', 'p_me', 'hel']
</code></pre>
<p>这是列表理解(<a href="https://docs.python.org/3.6/tutorial/datastructures.html#list-comprehensions" rel="nofollow noreferrer">https://docs.python.org/3.6/tutorial/datastructures.html#list-comprehensions</a>),您可以迭代生成的列表。你知道吗</p>
<p>它的var[开始:结束:步进]。单词[::-1]的意思是获取一个字母,从开头开始,在结尾结束,然后前进-1步,所以它会反转字符串</p>
<p>对于新值:</p>
<pre><code>word="10011100110000111010"
[word[4*l:4*(l+1)] for l in range(0, int(len(word)/4)+1)]
['1001', '1100', '1100', '0011', '1010']
[word[::-1][4*l:4*(l+1)] for l in range(0, int(len(word)/4)+1)]
['0101', '1100', '0011', '0011', '1001']
</code></pre>