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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:32:31+00:00 2026-06-04T16:32:31+00:00

I have a fairly basic question regarding python lists/dictionaries which I would like some

  • 0

I have a fairly basic question regarding python lists/dictionaries which I would like some help on.

I have some data relating to electric vehicles which have different characteristics. Each EV has an:

  • ID e.g. 12345
  • A battery size e.g. 24
  • A state of charge for each five minute period of the day e.g. 00:05:00 : 1; 00:10:00 : 0.95

How best do I go about this? I had been trying various combinations of lists/dicts but can’t quite get it to work. I’d like to be able to access the data by e.g.:

EV['ID'][2]['Batt']['SOC'][5] which would return e.g. 0.95 or
EV[12345]['Batt']['SOC'][5]

My latest attempt was:

EV = defaultdict(lambda: defaultdict(dict))

EV['ID']['Batt']['Time']=[]
EV['ID']['Batt']['SOC']=[]
EV['ID']['Batt']['Size'] = 24

However this didn’t allow for the entry of multiple IDs which are in another list admin[‘ID’]. It yielded:

{'ID': defaultdict....,{'Batt':{'SOC:[], 'Size':24, 'Time':[]}}}}

I would appreciate your help!

  • 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-04T16:32:32+00:00Added an answer on June 4, 2026 at 4:32 pm
    from collections import defaultdict
    import datetime
    
    class ElectricVehicle(object):
        ev_by_id = {}
        ev_by_battery = defaultdict(list)
    
        @classmethod
        def find(cls, id=None, battery=None):
            if id is not None:
                return [cls.ev_by_id[id]]
            elif battery is not None:
                return cls.ev_by_battery[battery]
            else:
                return []
    
        def __init__(self, id, battery, states):
            self.id = id
            ElectricVehicle.ev_by_id[id] = self
    
            self.battery = battery
            ElectricVehicle.ev_by_battery[battery].append(self)
    
            self.states = list(states)
    
        def state_at(self, time):
            return self.states[(time.hour*60 + time.minute)/5]
    
    ElectricVehicle(12345, 24, [0.99, 0.99, 0.99])
    ElectricVehicle(12346, 30, [0.90, 0.90, 0.89])
    
    evs = ElectricVehicle.find(battery=24)
    for ev in evs:
        time = datetime.time(0,3,0)    # 00:03:00
        print("{}: {}".format(ev.id, ev.state_at(time)))
    
    # will print "12345: 0.99"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

first post, so play nice! I have a fairly basic question about Python dictionaries.
All, This would seem like a fairly basic asp.net question - but in all
I am making a webapp. I have a fairly basic question about javascript performance.
basic c++ question i'm fairly sure. if i have a base class with a
I have a fairly involved managed data model which has a central object with
A fairly basic htaccess question, but I don't use it much, so i have
Hey I have a fairly basic question about regular expressions. I want to just
Question I have a fairly static website with just a few basic PHP usage.
I'm fairly new to MySQL and I need help with a relatively basic question.
I've been doing some simple web programming using python, and I have a basic

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.