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="Sean, post: 3897202"] I was able to do this by doing the following: page_data = [[start_position + 1 + n, x] for n, x in enumerate (page_data)] However, this creates a list of lists, each containing an int and a dictionary. I wanted to add it directly to the dictionary. I can add the key position to the dictionary when the data is created, but how would I assign the value in a list comprehension? [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
Best way to add a "position" value to each item in a list
Top