python - Best way to change specified indices of a list -


I immediately want to change some elements of the list.

Suppose we have these lists:

  list = [1, 2, 3, 4, 5, 6] idx = [1, 3, 4] New = [100, 200, 300]   

I change the element 1, 3, 4 with the list to new values For example:

  list [idx] = new   

hence the last list => is [1, 100, 3, 200, 300 , 6]

I know that you can use it in Matlab like this, but I should know what should I do in Python?

Note : I know that using loop is possible and it is possible to do this.


Edit : I want to use a pure Python solution.

Code> zip (idx, new): l [i] = n

Python itself does not support matlab style operation of the array, but if you are interested in that coding style , You can see it in Norma (see @Abernart's answer)

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -