Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8922867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:57:25+00:00 2026-06-15T06:57:25+00:00

I have Python code accessing data in a database (in Django): for result in

  • 0

I have Python code accessing data in a database (in Django):

for result in request.user.results.all():
    for word in result.word.all():
        data.append(dict(zip([str(word.type.type)], [str(word.word)])))

which displays ‘data’ as such:

[{'color': 'blue'}, {'kind': 'pencil'}, {'rating': 'high'}, {'color': 'red'}, {'kind': 'truck'}, {'rating': 'low'} and so on....

I want to rewrite the python code to display this instead:

[{'color': 'blue', 'kind': 'pencil', 'rating': 'high'}, {'color': 'red', 'kind': 'truck', 'rating': 'low'} and so on....

Are these two the same or does the location of the ‘{‘ matter? I wrote the code above but I’m not how (or if I need to) modify it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:57:27+00:00Added an answer on June 15, 2026 at 6:57 am

    It looks to me like your zipping together single-item lists to make single item dicts. I think what you want instead is:

    for result in request.user.results.all():
        data.append(dict([(word.type.type, word. word) for word in result.word.all()]))
    

    zip is typically used to make dicts in situations when you have two pre-existing lists, not so much when you’re constructing a dict from scratch from objects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some python code using shutil.copyfile: import os import shutil src='C:\Documents and Settings\user\Desktop\FilesPy'
I have Python code that pulls info from a sqlite database and then write
I have some python code that I wrote to convert a python list into
I have some python code that currently performs expensive computation by performing the computation
I have a C program with embedded python code. I have compiled python 2.7.2
I have the following Python code: cursor.execute("INSERT INTO table VALUES var1, var2, var3,") where
I have created some python code which creates an object in a loop, and
I have been writing Python code for only a couple of weeks, so I'm
I have a piece of Python code that is supposed to open a new
I have a simple python curses code that creates a subwindow. However, in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.