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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:20:24+00:00 2026-05-28T14:20:24+00:00

Hopefully I’m not missing something obvious… I’m creating a function that will ease in

  • 0

Hopefully I’m not missing something obvious…

I’m creating a function that will ease in creating specifically formatted JSON data from a Django query. However, this should be a purely python question.

I’d like to be able to convert all values with a given index to a specified format with a function like the folowing:

data = [['foo1','bar1'],['foo2','bar2']]
format = {1:'VALUE says Hello world'}

>> some_function(data, format) 
[['foo1','bar1 says Hello World'],['foo2','bar2 says Hello World']]

Basic idea:

def some_function(data, format):
    for row in data:
        for count, value in enumerate(row):
            if format.has_key(count):
                #do something to replace 'VALUE' with value
            else:
                #just use value, no changes
    return formatted_data

The root of this question is that the data goes directly to web and I’d like to define specific formatting based on what I’m passing through the generic function.

Edit for clarity:

What should I add to some_function() to convert the appropriate values in the data list to the format defined by the format dictionary?

  • 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-28T14:20:24+00:00Added an answer on May 28, 2026 at 2:20 pm
    def some_function(data, format):
        result = []
        for row in data:
            lst = []
            for count, value in enumerate(row):
                if count in format:
                    string = format[count].format(value)
                    lst.append(string)
                else:
                    lst.append(value)
            result.append(lst)
        return result
    
    
    data = [['foo1', 'bar1'], ['foo2', 'bar2']]
    format = {1: '{0} says Hello world'}
    print(some_function(data, format))
    # prints: [['foo1', 'bar1 says Hello world'], ['foo2', 'bar2 says Hello world']]
    

    The format you can use is explained in the docs.

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

Sidebar

Related Questions

Hopefully this will not spark a religious war... We have a web based app
Hopefully (but not necessarily) one that is independent of language or framework?
Hopefully this is something simple I am missing, I have an OL encompassing a
Hopefully this question has an easy answer. It's probably something stupid I'm doing! In
Hopefully this will be an easy question! I have two tables, a 'client(s)' table
Hopefully someone can give me a pointer. I have an application that makes several
Hopefully this will be an easy one to answer. I created a class in
Hopefully, this will be an easy answer for someone with Javascript time behind them...
Hopefully a nice simple one. I've got a php3 website that I want to
Hopefully can someone help me with an example, because I'm new in JSON: From

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.