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

  • Home
  • SEARCH
  • 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 8424589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:02:10+00:00 2026-06-10T04:02:10+00:00

I am iterating a dict created using the following. tree = defaultdict(partial(defaultdict, partial(defaultdict, list)))

  • 0

I am iterating a dict created using the following.

 tree = defaultdict(partial(defaultdict, partial(defaultdict, list)))
 for dt, hour, value in flat_list:
     tree[dt][hour]=[]
     tree[dt][hour].append(value)

My output looks like this:

 for k,v in tree.iteritems():
     2012-08-07 defaultdict(<functools.partial object at 0x1e0a050>, {'17': ['30']})
     2012-08-24 defaultdict(<functools.partial object at 0x1e0a050>, {'3': ['70']})

How do I get rid of this stuff? How do I iter like a regular dict?:

defaultdict(<functools.partial object at 0x1e0a050>
  • 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-10T04:02:12+00:00Added an answer on June 10, 2026 at 4:02 am

    You are already iterating over the default dicts like a regular dict, but you are printing the defaultdict representation too.

    To print these like you would print a regular dict, just turn them back into one:

     for k,v in tree.iteritems():
         print k, dict(v)
    

    Note that a defaultdict is a direct subclass of dict, apart from the updated __getitem__ behaviour and the updated __repr__ hook1, a defaultdict behaves exactly like a normal dict would, certainly when it comes to iterating.

    1__copy__ and __deepcopy__ are overridden too, to create a new defaultdict when using the copy module. A custom __reduce__ is provided for the pickle module for the same reasons.

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

Sidebar

Related Questions

Is iterating through the vector using an iterator and copying to a list the
Im iterating a list and getting hold of 2 fields Name and Url i
I was iterating through a table I had created and getting the first cell
I am interested in a dict implementation for Python that provides an iterating interface
What is the easiest way to convert Python dict e.g.: a = {'a': 'value',
Is it possible to add dict functionality to user created classes? ie: class Foo(object):
I've got a few lines of code for iterating over a dict within a
When using a SortedDictionary in Linq and iterating over the KeyValuePair it provides, can
Without iterating through each element, how do I create an array using new and
I know there are many dict to list questions on here but I can't

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.