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 6963767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:50:14+00:00 2026-05-27T15:50:14+00:00

In [1]: test = {} In [2]: test["apple"] = "green" In [3]: test["banana"] =

  • 0
In [1]: test = {}

In [2]: test["apple"] = "green"

In [3]: test["banana"] = "yellow"

In [4]: test["orange"] = "orange"

In [5]: for fruit, colour in test:
   ....:     print(fruit)
   ....:     
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-32-8930fa4ae2ac> in <module>()
----> 1 for fruit, colour in test:
      2     print(fruit)
      3 

ValueError: too many values to unpack

What I want is to iterate over test and get the key and value together. If I just do a for item in test: I get the key only.

An example of the end goal would be:

for fruit, colour in test:
    print(f"The fruit {fruit} is the colour {colour}")
  • 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-05-27T15:50:15+00:00Added an answer on May 27, 2026 at 3:50 pm

    Use items() to get an iterable of (key, value) pairs from test:

    for fruit, color in test.items():
        # do stuff
    

    This is covered in the tutorial.

    In Python 2, items returns a concrete list of such pairs; you could have used iteritems to get the same lazy iterable instead.

    for fruit, color in test.iteritems():
        # do stuff
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

elif(listb[0] == "-test"): run_all.set("testview") listb.pop[0] ERROR : Exception in Tkinter callback Traceback (most recent
I have a string which is like this: this is "a test" I'm trying
How can I test if a string contains only whitespace? Example strings: " "
I have a string in Bash: string="My string" How can I test if it
I have been trying to use the Perl utility/module "prove" as a test harness
<div> <div class="left"> <div align="center" class="node"> <div class="nodeText"> <h2 >test</h2> </div> <div class="node"> <h2>test</h2>
var textTitle = "this is a test" var result = textTitle.replace(' ', '%20'); But
I'm trying to find paragraphs with the id "test" and remove them from a
When I run this unit test: require 'test_helper' class MyControllerTest < ActionController::TestCase test "my
I have a nearly-boxplot like jitter-plot: dt <- rbind(se,cb,cb.se) qplot(ds, size, data=dt, geom="jitter", colour=root,

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.