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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:49:03+00:00 2026-05-14T16:49:03+00:00

Lets say i have a simple array of x rows and y columns with

  • 0

Lets say i have a simple array of x rows and y columns with corresponding values,
What is the best method to do 3 things?
How to insert, update a value at a specific row column? How to select a value for each row and column,

import sqlite3
con = sqlite3.connect('simple.db')
c = con.cursor()
c.execute('''create table simple (links text)''')
con.commit()

dic = {'x1':{'y1':1.0,'y2':0.0},'x2':{'y1':0.0,'y2':2.0,'y3':1.5},'x3':{'y2':2.0,'y3':1.5}}
ucols = {}
## my current thoughts are collect all row values and all column values from dic and populate table row and columns accordingly how to call by row and column i havn't figured out yet
##populate rows in first column
for row in dic:
    print row
    c.execute("""insert into simple ('links') values ('%s')"""%row)
con.commit()

##unique columns
for row in dic:
    print row
    for col in dic[row]:
        print col
        ucols[col]=dic[row][col]

##populate columns    
for col in ucols:
    print col
    c.execute("alter table simple add column '%s' 'float'" % col)
con.commit()

#functions needed
##insert values into sql by row x and column y?how to do this  e.g. x1 and y2 should put in 0.0
##I tried as follows didn't work
for row in dic:
    for col in dic[row]:
        val =dic[row][col]
        c.execute("""update simple SET '%s' = '%f' WHERE 'links'='%s'"""%(col,val,row))
con.commit()

##update value at a specific row x and column y?


## select a value at a specific row x and column y?
  • 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-14T16:49:04+00:00Added an answer on May 14, 2026 at 4:49 pm

    So you have a dictionary of dictionaries, that you want to convert into a SQL table.

    Steps I’d take

    1. Find the columns you’ll need.
    2. Create the table schema.
    3. Loop through each row.
      1. Compile the set of values for each column.
      2. Insert it.

    So:

    import sqlite3
    con = sqlite3.connect('simple.db')
    c = con.cursor()
    
    dic = {
        'x1':{'y1':1.0,'y2':0.0},
        'x2':{'y1':0.0,'y2':2.0,'y3':1.5},
        'x3':{'y2':2.0,'y3':1.5}
        }
    
    # 1. Find the unique column names.
    columns = set()
    for cols in dic.values():
        for key in cols:
           columns.add(key)
    
    # 2. Create the schema.
    col_defs = [
        # Start with the column for our key name
        '"row_name" VARCHAR(2) NOT NULL PRIMARY KEY'
        ]
    for column in columns:
        col_defs.append('"%s" REAL NULL' % column)
    schema = "CREATE TABLE simple (%s);" % ",".join(col_defs)
    c.execute(schema)
    
    # 3. Loop through each row
    for row_name, cols in dic.items():
    
        # Compile the data we have for this row.
        col_names = cols.keys()
        col_values = [str(val) for val in cols.values()]
    
        # Insert it.
        sql = 'INSERT INTO simple ("row_name", "%s") VALUES ("%s", "%s");' % (
            '","'.join(col_names),
            row_name,
            '","'.join(col_values)
            )
        c.execute(sql)
    

    Then your other questions are pretty simple:

    ## update value at a specific row x and column y?
    def set_cell(connection, x_name, y_name, value):
        sql = 'UPDATE simple SET %s="%s" WHERE row_name="%s"' % (
            y_name, value, x_name
            )
        connection.execute(sql)
    
    ## select a value at a specific row x and column y?
    def get_cell(connection, x_name, y_name):
        sql = 'SELECT %s FROM simple WHERE row_name="%s"' % (
            y_name, x_name
            )
        # Return the first row of results (there should be only one)
        # and the first column from that row
        return list(connection.execute(sql))[0][0]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have a simple 1D array with 10-20 entries. Some will be
Lets say that you have a following simple application: <form action=helloServlet method=post> Give name:<input
To keep things simple, lets say I have a Node class, each node has
Lets say I have a simple ecommerce site that sells 100 different t-shirt designs.
Lets say I have a class A that is fairly simple like this -
Let's say I have a simple ASP MVC3 list controller, with an add method,
I have an array and lets say I have 5 objects in it. The
Using ActionScript 3, suppose I have an array of numbers, lets say: 1, 2,
This is a pretty simple question.. lets say I have the following. wordArray WORD
Let's say I have some simple Javascript like: <script> var hello = function(){ alert(Hello

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.