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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:55:33+00:00 2026-05-31T01:55:33+00:00

I am new to python and I am trying to run following code: m=int(raw_input())

  • 0

I am new to python and I am trying to run following code:

m=int(raw_input())
l=[[0]*2]*m
for i in range(0,m):
    for j in range(0,2):
        l[i][j]=raw_input()
        print l
        print "-------"

Output:

3
1
[['1', 0], ['1', 0], ['1', 0]]
-------
2
[['1', '2'], ['1', '2'], ['1', '2']]
-------
3
[['3', '2'], ['3', '2'], ['3', '2']]
-------
4
[['3', '4'], ['3', '4'], ['3', '4']]
-------
5
[['5', '4'], ['5', '4'], ['5', '4']]
-------
6
[['5', '6'], ['5', '6'], ['5', '6']]

but, when i dry run the program the expected output should be

3
1
[['1', 0], ['1', 0], ['1', 0]]
-------
2
[['1', '2'], ['1', '2'], ['1', '2']]
-------
3
[['1', '2'], ['3', '2'], ['1', '2']]
-------
4
[['1', '2'], ['3', '4'], ['1', '2']]
-------
5
[['1', '2'], ['3', '4'], ['5', '2']
-------
6
[['1', '2'], ['3', '4'], ['5', '6']]

Its like after each iteration list is reassigned, but as I am incrementing ‘i’ list elements should be like the expected output. Please i need 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-05-31T01:55:35+00:00Added an answer on May 31, 2026 at 1:55 am
    s * n, n * s    ==>   n shallow copies of s concatenated 
    

    Note that the copies are shallow; nested structures are not copied.
    This often haunts new Python programmers; consider:

    >>> lists = [[]] * 3
    >>> lists
    [[], [], []]
    >>> lists[0].append(3)
    >>> lists
    [[3], [3], [3]]
    

    You can change your code to:

    l = [[0 for i in range(2)] for j in range(m)]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to python but I've run into a hitch when trying to implement
I'm very new to python and trying to run a piece of Django code
I am trying to run a Python program using PHP. Here's the code $command
I am trying to open python prompt and run the below code: >>> a=open(Andrew_Smith_(author/education_professional)_0,'w')
I am new to python and I'm trying to create a program that creates
I'm completely new to Python and I've been trying to make a fibonacci program
Im new two python and am trying to grow a dictionary of dictionaries. I
I'm brand new at Python and I'm trying to write an extension to an
I am pretty new to python and working with firmata I am trying to
I'm really new to Python. I'm trying to import a third party module called

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.