I had a requirement in one of my codes to access values from a list of dictionaries that I initialized with default values. My object looked like this:  &gt;&gt;&gt; lengths = [{"max_len":0,"eq_len":True}] * 7 &gt;&gt;&gt; print(lengths)  [{'max_len': 0, 'eq_len': True}, {'max_len': 0, 'eq_len': True}, {'max_len': 0, 'eq_len': True}, {'max_len': 0, 'eq_len': True}, {'max_len': 0, 'eq_len': True}, {'max_len': 0, 'eq_len': True}, {'max_len': 0, 'eq_len': True}]   Surprisingly, when I'm trying to update any one of the values in this lengths object directly, all the other objects are also getting updated. For ex:  &gt;&gt;&gt; col_lengths[0]["max_len"] = 10 &gt;&gt;&gt; print(col_lengths)  [{'max_len': 10, 'eq_len': True}, {'max_len': 10, 'eq_len': True}, {'max_len': 10, 'eq_len': True}, {'max_len': 10, 'eq_len': True}, {'max_len': 10, 'eq_len': True}, {'max_len': 10, 'eq_len': True}, {'max_len': 10, 'eq_len': True}]  &gt;&gt;&gt; col_lengths[4]["eq_len"] =  False      &gt;&gt;&gt; print(col_lengths)  [{'max_len': 10, 'eq_len': False}, {'max_len': 10, 'eq_len': False}, {'max_len': 10, 'eq_len': False}, {'max_len': 10, 'eq_len': False}, {'max_len': 10, 'eq_len': False}, {'max_len': 10, 'eq_len': False}, {'max_len': 10, 'eq_len': False}]   Looks like this behavior is unexpected. Or am I doing something wrong? Can someone please help me with this?
410
I needed to create a list of lists in Python, so I typed the following: my_list = [[1] * 4] * 3  The list looked like this: [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]]    Then I changed one of the innermost values: my_list[0][0] = 5  Now my list looks like this: [[5, 1, 1, 1], [5, 1, 1, 1], [5, 1, 1, 1]]    which is not what I wanted or expected. Can someone please explain what's going on, and how to get around it?
27093
I occasionally see the list slice syntax used in Python code like this:  newList = oldList[:]   Surely this is just the same as:  newList = oldList   Or am I missing something?
87459
Basically I have a setup like the following:  Array (  [0] =&gt; Array ( [0] =&gt; stdClass Object ( [nid] =&gt; 1 [title] =&gt; title1 [uid] =&gt; 1 [parent] =&gt; 0 [weight] =&gt; -15 [name] =&gt; name1 [value] =&gt; 0 )                [1] =&gt; stdClass Object ( [nid] =&gt; 2 [title] =&gt; title2 [uid] =&gt; 1 [parent] =&gt; 0 [weight] =&gt; -7 [name] =&gt; name2 [value] =&gt; 100 )                [2] =&gt; stdClass Object ( [nid] =&gt; 3 [title] =&gt; title3 [uid] =&gt; 2 [parent] =&gt; 0 [weight] =&gt; -1 [name] =&gt; name3 [value] =&gt; 0 )                [3] =&gt; stdClass Object ( [nid] =&gt; 4 [title] =&gt; title4 [uid] =&gt; 2 [parent] =&gt; 0 [weight] =&gt; 1 [name] =&gt; name4 [value] =&gt; 80 )               )   )   What I need is a way to sort all the arrays inside the parent array by the [value] key in the Object. I've been trying for about 2 days now with usort and different methods but I just can't seem to get my head around it. The [value] key will range anywhere from 0 to 100 and I need all of the arrays sorted in decreasing order (IE: 100 down to 0).
29326
Here is my test code and picture:  import bpy   # Simple property reading/writing from ID properties. # This is what the RNA would do internally. def get_float(self):     return self["testprop"]   def set_float(self, value):     self["testprop"] = value  #bpy.types.Scene.test_float = bpy.props.FloatProperty(get=get_float,set=set_float) bpy.types.Scene.test_float = bpy.props.FloatProperty()   bpy.context.scene.test_float = 12.34     When I don't explicitly set the "get/set" function for my property, after assigning the value, I can get the property value by 'scene["test_float"]', but if I explicitly set the "get/set" function, then if I try to type in the same commands, I will receive a error "KeyError: 'bpy_struct[key]: key "test_float" not found'" . So what should I do to get the same results by using explicitly  "get/set" function?
17166
I have a list of integers, List&lt;Integer&gt; and I'd like to convert all the integer objects into Strings, thus finishing up with a new List&lt;String&gt;.  Naturally, I could create a new List&lt;String&gt; and loop through the list calling String.valueOf() for each integer, but I was wondering if there was a better (read: more automatic) way of doing it?
53456
What is the difference between:  some_list1 = [] some_list1.append("something")   and  some_list2 = [] some_list2 += ["something"]
56234
I am trying to modify an object after importing it. This post is related to   import bpy full_path_to_file = "C:\\Users\\xyz\\Documents\\test.obj" bpy.ops.import_scene.obj(filepath=full_path_to_file) # create the material mat = bpy.data.materials.new('MaterialName') mat.diffuse_color = (1.0,0.0,1.0) mat.diffuse_shader = 'LAMBERT' mat.diffuse_intensity = 1.0  # get the object obj = bpy.data.objects['Cube']  # get the material mat = bpy.data.materials['MaterialName']  # assign material to object obj.data.materials.append(mat)   I wanted to add a material to the imported object but that is not happening. So I tried to scale it even that is not happening.  I realized that no operation is being performed on the imported objects. But the same operations are executing on the objects that are created (i.e. not imported).  Any help would be appreciated.
80273
If I have a dictionary like:  { 'a': 1, 'b': 2, 'c': 3 }   How can I convert it to this?  [ ('a', 1), ('b', 2), ('c', 3) ]   And how can I convert it to this?  [ (1, 'a'), (2, 'b'), (3, 'c') ]
1704
This has always confused me. It seems like this would be nicer:  my_list = ["Hello", "world"] print(my_list.join("-")) # Produce: "Hello-world"   Than this:  my_list = ["Hello", "world"] print("-".join(my_list)) # Produce: "Hello-world"   Is there a specific reason it is like this?
86980
I've only just started studying the Blender Python API. I'm writing a script (see below) to automate something I've done by hand : joining two adjacent cubes and cleaning up the resulting mesh.   After joining and removing doubles, I expect to have 12 vertices instead of 16 in the resulting object. In the Info header, this seems to be the case, but when I print to the windows terminal I still see 16. Also I do see the output from remove_double(), here's a screenshot :    So what's wrong here ? What is the right way to access an object's mesh, and count its vertices ?  Joao  import bpy  # Create two adjacent cubes and join them bpy.ops.mesh.primitive_cube_add(location=(1,0,0)) ob = bpy.context.object bpy.ops.mesh.primitive_cube_add(location=(3,0,0)) ob.select = True bpy.ops.object.join()  # Expect 16 vertices, 24 edges, 12 faces result = bpy.context.object print(str(len(result.data.vertices)))  # Go to edit mode, remove double vertices bpy.ops.object.mode_set(mode = 'EDIT') bpy.ops.mesh.remove_doubles()  # Expect 12 vertices, 20 edges, 11 faces result = bpy.context.object print(str(len(result.data.vertices)))
56203
I have a list declared like this -  m_list = own.get("m_list")   Now the problem is I can't access this list from another object. How do I declare the list so that I can access it from another object. I have to check whether or not an element exists.
2267
What's the difference between the list methods append() and extend()?
30825
I'm writing an operator for which it is crucial that every time it gets called all the properties are set to their default values.   The ops.object.delete has 1 param. use_global. It is always false, no matter what the user put in last time it got called. I would like to replicate exactly that.   (For example: I want to modify delta scale. The default val for my_factor is 1, so nothing happens until the user alters that number. If the user calls the operator again, it will have stored whatever number the user has used last, however I want it to always start with 1.)
7281
I have a list of dictionaries and want each item to be sorted by a specific value. Take into consideration the list: [{'name':'Homer', 'age':39}, {'name':'Bart', 'age':10}]  When sorted by name, it should become: [{'name':'Bart', 'age':10}, {'name':'Homer', 'age':39}]
104197
When i create new User Account and login with that credentials, it gives me this problem if admin doesnt have set thier values yet !!!**  AllotmentList = [select id, Days_Remaining__c from PTO_Allotment__c where Year__c =:year and Employee__c=:EmployeeList[0].id LIMIT 100]; //access only Current user Allotment details                 //to handle Listoutof Bound Exception wrote if-else          if(AllotmentList.size()&gt;0)         {         requests.PTO_Allotment__c=AllotmentList[0].id;         requests.Days_Remaining__c=AllotmentList[0].Days_Remaining__c;         }         else         {             //write a code when AllotmentList is empty ....         }
2532
I have a dictionary: keys are strings, values are integers.  Example:   stats = {'a':1000, 'b':3000, 'c': 100}   I'd like to get 'b' as an answer, since it's the key with a higher value.  I did the following, using an intermediate list with reversed key-value tuples:  inverse = [(value, key) for key, value in stats.items()] print max(inverse)[1]   Is that one the better (or even more elegant) approach?
98138
In Python, I can do:  &gt;&gt;&gt; list = ['a', 'b', 'c'] &gt;&gt;&gt; ', '.join(list) 'a, b, c'   Is there any easy way to do the same when I have a list of objects?  &gt;&gt;&gt; class Obj: ...     def __str__(self): ...         return 'name' ... &gt;&gt;&gt; list = [Obj(), Obj(), Obj()] &gt;&gt;&gt; ', '.join(list) Traceback (most recent call last):   File "&lt;stdin&gt;", line 1, in &lt;module&gt; TypeError: sequence item 0: expected string, instance found   Or do I have to resort to a for loop?