Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
Best way to add a "position" value to each item in a list
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Carl Banks, post: 3897222"] Not really, but if you want to avoid the delay in setting the dictionary elements (I'm guessing that is why you don't want to iterate over the list--and parenthetically it's not iterating over the list but adding dictionary items that is driving the time, and that cost is unavoidable), you should consider adding the position elements on demand. That is, instead of running a big loop once to add position to all ten million elements, just run the loop on individual pages. def get_page(start,end): page = list_data[start:end] for i,item in enumerate(page): page['position'] = start+i return page That might not work depending on what you are doing but you should consider it. Carl Banks [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
Best way to add a "position" value to each item in a list
Top