126k views
5 votes
Given a list lst, write a 'for' loop that replaces each element of lst with alternating 0's and 1's, starting with 0. For example, if lst is [5, 3, 7, 0], it should become [0, 1, 0, 1], and if lst is [1, 2, 3], it should become [0, 1, 0] *

User Gpampara
by
5.5k points

1 Answer

4 votes

Step-by-step explanation:

c++:

for(int i =0;i<list.size();i++){

list[i]=i%2;

}

python 3:

for i in range(len(list)):

list[i]=i%2

User Glinkot
by
5.6k points