How to take multiple values from a python list?
<p>I am creating a program that takes user input stores it in a list and then multiplies by either 5 or 1 alternating between each number. eg the first value is multiplied by 5 and the next 1 and so on. I want to remove all the values that i would multiply by 5 and add them to a separate list. How would this be done? </p>

<pre><code>list1=[1,2,3,4]
list2=List1[???]
</code></pre>

<p>To get every other element, you could use a slice with a stride of two:</p>

<pre><code>&gt;&gt;&gt; list1 = [1,2,3,4]
&gt;&gt;&gt; list2 = list1[::2]
&gt;&gt;&gt; list2
[1, 3]
</code></pre>

<p>You can use a similar technique to get the remaining elements:</p>

<pre><code>&gt;&gt;&gt; list3 = list1[1::2]
&gt;&gt;&gt; list3
[2, 4]
</code></pre>

<p>For further information, see <a href="http://stackoverflow.com/questions/509211/explain-pythons-slice-notation">Explain Python&#39;s slice notation</a></p>

python