S
S
s1lver0k2017-04-06 13:05:47
Python
s1lver0k, 2017-04-06 13:05:47

(Python3) how to replace elements in a list?

There is a list with random numbers

n = 5
row = np.random.randint(1, 10, n)

you need to change the elements in it,
if paired then by 2-i^2 #i - number in order.
unpaired by 12
I will be grateful for any information.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2017-04-13
@s1lver0k

row = [2-i^2 if row[i]%2 == 0 else 12 for i in range(n)]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question