I can not understand how it is possible in Python to add data to the dictionary (array) at a specific index, without using for and append cylinders.
The data is returned by a Solr filter, but it is not assigned in the right way ( append ).
And I need the data to be contained as follows. For the time being, for example, I added them manually:
clean_data = { 'results': [ { 'name': u'Classic', 'select_url': '/ru/catalogue/category/Classic' }, { 'name': u'Common', 'select_url': '/ru/catalogue/category/Common' } ] } For example, the Classic object is under the index [0] , followed by the object [1] common object was added immediately under the index [1] .
Of course, I could use for-loop , and append, but this creates a problem, when you re-apply the common object is written under the index [0], and classic under [1], but you need the collection to be constant, i.e. dict[common[0],classic[1]] , not dict[common[0]], dict[common[1]] , due to the logic of Solr.
And for this, I would like to initially assign the [] index of the incoming object, and change the size of the collection depending on the amount of incoming data. in C code, this was done as follows: dict.length = 1 ; dict[0] = 'common' , or dict.set(0) = 'common' , but how to do this in python. The point is not to add data through for and append , since that's my problem.