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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:24:50+00:00 2026-06-17T18:24:50+00:00

I am generating a list of computers attached to a server. For each computer

  • 0

I am generating a list of computers attached to a server. For each computer I gather a list of properties. I am new to Python and programming and am finding my solution rather clunky.

I was doing this with lists. I have a master list: computer_list and each computer is another list, with attributes such as status, date, profile, etc.

computer_list = [cname1, cname2, cname3]
cname1 = ['online', '1/1/2012', 'desktop']

The downsides of this method are becoming obvious the more I work and change this program. I’m hoping for something more intuitive. I looked into dictionaries, but that solution seems almost as convoluted as mine. The list within a list is workable but not readable once I start iterating and assigning. I am sure there is a better way.

  • 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-17T18:24:51+00:00Added an answer on June 17, 2026 at 6:24 pm

    Make each computer an object:

    class Computer(object):
        def __init__(self, name, status, date, kind):
            self.name   = name
            self.status = status
            self.date   = date
            self.kind   = kind
    
        @classmethod    # convenience method for not repeating the name
        def new_to_dict(cls, name, status, date, kind, dictionary):
            dictionary[name] = cls(name, status, date, kind)
    

    Then store these in a dictionary or list.

    computer_list = []
    computer_list.append(Computer("rainier", "online", "1/1/2012", "desktop"))
    
    computer_dict = {}
    Computer.new_to_dict("baker", "online", "1/1/2012", "laptop", computer_dict)
    

    Now when you iterate over them, it’s straightforward:

    for comp in computer_list:
        print comp.name, comp.status, comp.date, comp.kind
    

    You can also define __str__() on the class to define how they are displayed, and so on.

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

Sidebar

Related Questions

I am generating a list from sql server, filtering it based on new and
Hi i am generating checkbox list by using a for each loop, I want
I am having some problems generating a list for a class in Python. I
I'm generating an unordered list through javascript (using jQuery). Each listitem must receive its
I have many parabolas that are intersecting each other. I am generating a list
I'm generating List<int> x and List<int> y from List<Point> p using this code: List<int>
I'm generating a list from some string up to 4 NSUInteger total = MIN(4,
Friends i'm using string builder for generating Passenger List in which i have used
I'm currently generating a definition list with PHP Markdown Extra with the following syntax:
I am currently generating a list of links (to files in a single directory)

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.