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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:06:20+00:00 2026-05-31T15:06:20+00:00

I would like to move more than one item from one list to another.

  • 0

I would like to move more than one item from one list to another.

list1 = ['2D','  ','  ','  ','  ','  ','  ','  ','  ']
list2 = ['XX','XX','5D','4S','3D','  ','  ','  ','  ']
list3 = ['XX','XX','XX','8C','7H','6C','  ','  ','  ']

In the code above ' ' is a double space

I would like to be able to move '5D','4S','3D' from list2 onto '8C','7H','6C' in list3.

I’ve tried the code below but it doesn’t work.

list1 = ['2D','  ','  ','  ','  ','  ','  ','  ','  ']
list2 = ['XX','XX','5D','4S','3D','  ','  ','  ','  ']
list3 = ['XX','XX','XX','8C','7H','6C','  ','  ','  ']


items_to_be_moved = list2[list2.index('XX')+2 : list2.index('  ')]

list3[list3.index('  ')] = items_to_be_moved
del list2[list2.index('XX')+2 : list2.index('  ')]

print('list2',list2)
print('list3',list3)

and this returns

list2 ['XX', 'XX', '  ', '  ', '  ', '  ']
list3 ['XX', 'XX', 'XX', '8C', '7H', '6C', ['5D', '4S', '3D'], '  ', '  ']

However, i dont want to use list2.index('XX')+2, i would like to use a code that gives the last index of 'XX' just like list2.index(' ') gives the first index of ' '.

Also, i dont want the moved items to be in a separate list of their own within another list.
For example: instead of returning

"list3 ['XX', 'XX', 'XX', '8C', '7H', '6C', ['5D', '4S', '3D'], '  ', '  ']"

the list

"list3 ['XX', 'XX', 'XX', '8C', '7H', '6C','5D', '4S', '3D', '  ', '  ']"

should be returned.

  • 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-31T15:06:21+00:00Added an answer on May 31, 2026 at 3:06 pm

    To replace the correct items, use slice assignment.

    list1 = ['2D','  ','  ','  ','  ','  ','  ','  ','  ']
    list2 = ['XX','XX','5D','4S','3D','  ','  ','  ','  ']
    list3 = ['XX','XX','XX','8C','7H','6C','  ','  ','  ']
    
    list3[3:6] = list2[2:5]
    
    print list3
    # ['XX', 'XX', 'XX', '5D', '4S', '3D', '  ', '  ', '  ']
    

    If you want to start from after the final consecutive 'XX', you can use:

    from itertools import takewhile
    i = sum(1 for _ in takewhile(lambda elem: elem == 'XX', list3))
    
    list3[i:i+3] = list2[i-1:i+2]
    

    to find the index of the last one.

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

Sidebar

Related Questions

I'm using a ContentPlaceHolder and would like to move the onload=Carousel() from the body
I have two divs. I would like to move/populate the text from div id
I would like an animation in which the letters of a word move from
I would like to move data back and fourth between clojure applications. Application settings
I would like to move some files around in Visual Studio. But I see
I would like to move an imageView contained on a cell and it works
I would like to move the media directory in for my magento store to
Please take a look at this screenshot first: I would like to move the
I am using the jQuery DataTables plugin. I would like to move the search
I have a simple 'repeat with' in an AppleScript, and would like to move

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.