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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:14:05+00:00 2026-06-06T10:14:05+00:00

in my python code i want to create a list of lists…in a loop

  • 0

in my python code i want to create a list of lists…in a loop …
but after completion of the loop i end up with the same list in all elements…is it because the lists are pointed to and not stored ? If so, how can i come up with a solution to my problem ?
Following is my code

    list_lists=list()
    list_temp=list()
    for i in xrange(n):
        ind_count =0
        del list_temp[0:len(list_temp)]
        for j in xrange(no_words):
            if inp[i] == words[j]:
                list_temp.append(j)
        list_lists.append(list_temp)
  • 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-06T10:14:07+00:00Added an answer on June 6, 2026 at 10:14 am

    Instead of deleting the items of your list (del list_temp[0:len(list_temp)]) just assign a new list: list_temp = list(). You can also use the shorthand: list_temp = []

    The problem that you are facing is that you are always reusing the same list you created in the second line: list_temp = list(). You are just inserting references to this one list over and over again.

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

Sidebar

Related Questions

i want to make a system call in my python code but the problem
I want to create a list (not implying Python List ) of error messages
I have a list of lists and I want to create multiple smaller lists
I want to execute python code from C# with following code. static void Main(string[]
I want to execute some Python code, typed at runtime, so I get the
I write a lot of Python code where I just want to read a
I am managing a quite large python code base (>2000 lines) that I want
with this python 2.7.3 (or 2.7.0) code I want to change the value of
I have those two lines of code written in python i want to convert
I'm working on a simple GUI code editor in Python, and I want to

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.