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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:48:54+00:00 2026-06-07T05:48:54+00:00

I am trying to make a duplicate list of lists and change one element

  • 0

I am trying to make a duplicate list of lists and change one element to another within the nested lists of the duplicate list but am having some trouble.
How I made the duplicate list:

order = [['yhjK', 'F'], 'gap', ['bcsA', 'F'], ['bcsB', 'F'], ['bcsZ', 'F'], 'gap', ['yhjK', 'R']]
#order_1 = list(order) #this makes the duplicate list as well
order_1 = []
for x in order:
    order_1.append(x)

How I changed the elements:

for item in order_1:
    for n,i in enumerate(item):
            if i=='R':
                    item[n]='F'
            if i=='F':
                    item[n]='R'

I want to replace all the ‘F’ with ‘R’ and vice versa. This accomplishes that but the original list ‘order’ is changed as well. I only want the second list to be changed and can’t figure out what is the problem with my code.

What I get:

order = [['yhjK', 'R'], 'gap', ['bcsA', 'R'], ['bcsB', 'R'], ['bcsZ', 'R'], 'gap', ['yhjK', 'F']]
order_1 = [['yhjK', 'R'], 'gap', ['bcsA', 'R'], ['bcsB', 'R'], ['bcsZ', 'R'], 'gap', ['yhjK', 'F']]

What I want:

order = [['yhjK', 'F'], 'gap', ['bcsA', 'F'], ['bcsB', 'F'], ['bcsZ', 'F'], 'gap', ['yhjK', 'R']]
order_1 = [['yhjK', 'R'], 'gap', ['bcsA', 'R'], ['bcsB', 'R'], ['bcsZ', 'R'], 'gap', ['yhjK', 'F']]

Thanks everyone!

  • 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-07T05:48:56+00:00Added an answer on June 7, 2026 at 5:48 am

    What you’re doing here is a shallow copy of the list, so when you change the copy, the original changes as well. What you need is deepcopy

    import copy
    order = [['yhjK', 'F'], 'gap', ['bcsA', 'F'], ['bcsB', 'F'], ['bcsZ', 'F'], 
    'gap', ['yhjK', 'R']]
    order_1 = copy.deepcopy(order)
    
    # Now changing order_1 will not change order
    order_1[1] = ['TEST LIST']
    print order[1] # Prints 'gap'
    print order_1[1] # Prints '['TEST LIST']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How to make drag-and-drop from one list to another in C#/WindowsForms? I
Possible Duplicate: C# full screen console? I am trying to make one of my
I am trying to make a generic Duplicate linq extension method. But I cannot
Possible Duplicate: Checkbox size I'm trying to make some checkboxes display larger in most
Possible Duplicate: MVC3 custom validation: compare two dates I am trying to make a
Possible Duplicate: how to make phone call by using objective c? I am trying
I'm trying to add sequence of tags to a list subjects. I wouldn't make
I'm having some issues trying to retrieve unique values from a DataSet in csharp,
I'm trying to make an Applescript that takes a list of names and makes
Possible Duplicate: How to clone ArrayList and also clone its contents? trying to make

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.