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

The Archive Base Latest Questions

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

Using Python I managed to make myself a kind of dictionary of terms and

  • 0

Using Python I managed to make myself a kind of dictionary of terms and their meaning and it’s rather big – x00,000 items (can’t estimate right now as they are stored in multiple files by first letter).
Files are pickled dictionary objects with this structure:

dict{word, (attribute,
            kind,
            [meanings],
            [examples],
            [connections]
            )
    }

If it matters it’s Python dictionary object, with key as string and value as tuple, and then this tuple consists of either string or list objects.

Now I plan to put them all in sqlite3 database as it’s easy with Python. Before I do that I thought to ask for advice if sqlite3 if good choice as I’ve never done any real database task before.

I know that answer depends of what I want to do with this data (besides it’s structure), but let’s say I just want it to be stored locally in one place (file) and be reasonable easy to access (query) and possibly transform.

  • 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-26T16:14:27+00:00Added an answer on May 26, 2026 at 4:14 pm

    Yes, I’ve used sqlite3 for this kind of thing. The dictionary values had to first be pickled though:

    import sqlite3
    import pickle
    import collections
    
    class DBDict(collections.MutableMapping):
        'Database driven dictlike object (with non-persistent in-memory option).'
    
        def __init__(self, db_filename=':memory:', **kwds):
            self.db = sqlite3.connect(db_filename)
            self.db.text_factory = str
            try:
                self.db.execute('CREATE TABLE dict (key text PRIMARY KEY, value text)')
                self.db.execute('CREATE INDEX key ON dict (key)')
                self.db.commit()
            except sqlite3.OperationalError:
                pass                # DB already exists
            self.update(kwds)
    
        def __setitem__(self, key, value):
            if key in self:
                del self[key]
            value = pickle.dumps(value)
            self.db.execute('INSERT INTO dict VALUES (?, ?)', (key, value))
            self.db.commit()
    
        def __getitem__(self, key):
            cursor = self.db.execute('SELECT value FROM dict WHERE key = (?)', (key,))
            result = cursor.fetchone()
            if result is None:
                raise KeyError(key)
            return pickle.loads(result[0])
    
        def __delitem__(self, key):
            if key not in self:
                raise KeyError(key)
            self.db.execute('DELETE FROM dict WHERE key = (?)', (key,))
            self.db.commit()
    
        def __iter__(self):
            return iter([row[0] for row in self.db.execute('SELECT key FROM dict')])
    
        def __repr__(self):
            list_of_str = ['%r: %r' % pair for pair in self.items()]
            return '{' + ', '.join(list_of_str) + '}'
    
        def __len__(self):
            return len(list(iter(self)))
    
    
    
    >>> d = DBDict(raymond='red', rachel='blue')
    >>> d
    {'rachel': 'blue', 'raymond': 'red'}
    >>> d['critter'] = ('xyz', [1,2,3])
    >>> d['critter']
    ('xyz', [1, 2, 3])
    >>> len(d)
    3
    >>> list(d)
    ['rachel', 'raymond', 'critter']
    >>> d.keys()
    ['rachel', 'raymond', 'critter']
    >>> d.items()
    [('rachel', 'blue'), ('raymond', 'red'), ('critter', ('xyz', [1, 2, 3]))]
    >>> d.values()
    ['blue', 'red', ('xyz', [1, 2, 3])]
    

    The above will keep you database in a single file. You can navigate the object like a regular python dictionary. Since the values are pickled in a single field, sqlite won’t give you any additional query options. Other flatfile storage will have similar restrictions. If you need to write queries that traverse a hierarchical structure, consider using a NoSQL database instead.

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

Sidebar

Related Questions

Using Python 2.6, is there a way to check if all the items of
When starting a django application using python manage.py shell , I get an InteractiveConsole
In Django I am using two applications: python manage.py startapp books python manage.py startapp
Using Python I want to be able to draw text at different angles using
Using python 2.4 and the built-in ZipFile library, I cannot read very large zip
Using Python, how would I go about reading in (be from a string, file
Using Python's Imaging Library I want to create a PNG file. I would like
Using Python how do you reduce a list of lists by an ordered subset
Using Python, I want to know whether Java is installed.
Using Python module re, how to get the equivalent of the \w (which matches

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.