0
How can I write this in one line? Help me š„¹
for element in B: if element: C.append(A[i]) i +=1
3 Answers
0
C = [ element for element in B if element ]
read about list comprehension.
0
i, C = len(B), [A[_] for _ in range(len(B)) if B[_]]
0
import numpy
def elements_vector_true():
A, B = numpy.random.randint(10, size = 10), numpy.random.randint(10, size = 10)%2==0
print(f"Vector A: {A}")
print(f"Vector B: {B}\n")
i, C = 0, []
print("The vector A elements wich position of the vector B elements are true are:")
for element in B:
if element:
C.append(A[i])
i +=1
print(C)
elements_vector_true()
#This's the code complete. I hope you help me, and if it cannot, also thanks š
My code:
https://code.sololearn.com/cOcRd5u4gEMO/?ref=app