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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:05:40+00:00 2026-06-01T09:05:40+00:00

I have a string and a list of objects: gpl = %(id)s : %(atr)s

  • 0

I have a string and a list of objects:

gpl = "%(id)s : %(atr)s"

objects = [{'id':1, 'content':[{'atr':'big', 'no':2}]},  {'id':2, 'content': [{'atr':'small', 'no':3}]}]

for obj in objects:
   for con in obj['content']:
       print gpl %(obj,con)

I get:

TypeError: format requires a mapping

How would I print this? I am trying to print:

1 : big
2 : small

Thank you

  • 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-01T09:05:41+00:00Added an answer on June 1, 2026 at 9:05 am

    Since your formatting string uses named parameters:

    gpl = "%(id)s : %(atr)s"
    

    You need to provide keys (the names) in a dictionary as an argument to reference back to named formatting keys in the formatting string:

    print gpl % {'id': obj['id'], 'atr': con['atr']}
    

    So your code would be:

    for obj in objects:
        for con in obj['content']:
            print gpl% {'id': obj['id'], 'atr': con['atr']}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two complex (i.e. objects with string, int, double, List and other home
I have method that parses a list of String records into objects and returns
I have a list of objects each with a child list of string. I
I have this sample code. List<Dictionary<string,string>> objects = new List<Dictionary<string,string>>(); foreach (string url in
I have a list of objects and I want to print them in a
i have a list of objects in a collection. Each object has a string
I have a list of objects. E.g. List<coin> where they contain a string(denom) and
I have a List of string objects which represent process names. I want to
I have a servlet with several methods that get a list of objects from
I have filled List<Object1> Object 1 contain 2 fields (int id & string name)

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.