Category:Microcomputer softwareQ:
How to change a value within a list based on a list item Python
I have 2 lists, first list the main_list:
main_list = [5.0, 4.0, 3.0, 2.0, 1.0, 0.0]
second list:
point_in_main_list = [0, 1, 2, 3, 4, 5]
I would like to know how to loop through the point_in_main_list and change the value of the corresponding item in main_list to 0.
Output would be:
main_list = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
Any help would be greatly appreciated.
A:
You can use a dictionary:
mydict = {x: 0 for x in main_list}
for x, y in zip(point_in_main_list, main_list):
mydict[x] = y
Q:
I need help understanding the use of this code
I need to completely understand this piece of code and how it works. I tried reading many guides online and following them, but I still have a hard time understanding the code.
protected static void addSetter(Class c) throws NoSuchFieldException, IllegalAccessException {
Field f = c.getDeclaredField("this$0");
f.setAccessible(true);
f.set("this", c);
f.setAccessible(false);
}
I don't understand what "this$0" is. Is it a reference to the array? What does "$" mean? And why can't I set accessible to false? I'm only trying to understand how this code works. Thank you
A:
this$0 is a placeholder for the generic type parameter c in the parameter list of addSetter. When addSetter is called, the receiver (the this) is assigned to that type parameter.
$ is the "dollar" character in Java identifiers. I think of it as special, like a single quote mark, in that it's used to delim ac619d1d87
Related links:
Comments