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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:01:32+00:00 2026-06-12T02:01:32+00:00

people. I’m python newbie. I have two def functions as below under a class.

  • 0

people. I’m python newbie. I have two def functions as below under a class.

def add_item(self, itemID, itemlist):
    lines = []

    self.itemID = itemID
    self.itemlist = itemlist

    for line in self.itemID, itemlist:
        lines.append(line)

and

def get_keys(self):
    i = []
    i.append(self.itemID)
    return i 

If I do

example.add_item('abc', item list)
example.add_item('abcd', item list)
example.add_item('abce', item list)

then when I do

example.get_keys()

It should give:

['abc', 'abcd', 'abce']

but mine only gives the latest one that is ['abce'].

Can anyone please let me know how to fix?

  • 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-12T02:01:34+00:00Added an answer on June 12, 2026 at 2:01 am

    If I understand correctly, you want to add several couple of key and item_list to your example, and be able to retrieve the keys you added so far ? The easiest is to store the keys and the itemlist in two lists

    Assuming that you initialize your object as such

    def __init__(self, *args, **kwargs):
       self.itemID = []
       self.itemlist = []
       ...
    

    Now, your add_item can simplify in

    def add_item(self, itemID, itemlist):
        self.itemID.append(itemID)
        self.itemlist.append(itemlist)
    

    and your get_key is only:

    def get_keys():
        return self.itemID
    

    • Note that the get_key is exactly the one you have suggested, just simpler (no need to create a temporary list).

    • When you do

      lines = []
      for line in self.itemID, itemlist:
          lines.append(line)
      

      line first takes the value self.itemID, then itemlist. Eventually, your lines is just [self.itemID, itemlist]. Probably not what you had in mind.

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

Sidebar

Related Questions

Hi people I have the following code (shown below) and I am trying to
Hello people i have this script <a class=clickMe toggle=first>Text 1</a> </br> <div id=first class=text>
People familiar with Homographies will know that you have to normalize it dividing by
people. I have slight problem with GD2 text on image. I have everything working
people. For a academic exercise i have to implement a program in c for
People use void main() /*empty parens ()*/ I have been taught to write void
People often throw around the terms IR, ML, and data mining, but I have
Hi people I have been at this for like 5 days and could not
People have been able to build PCRE (or a subset of) by copying the
people. I hope you can help me. In our development process we have a

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.