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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:28:13+00:00 2026-05-31T03:28:13+00:00

I basicly need to be able to restrict the items that can be appended

  • 0

I basicly need to be able to restrict the items that can be appended in a list. Just like in a solitaire game, i need an item to be added to a list if it is meant to follow that item alphabetically and if it doesnt then an error is returned. for instance; letter d can be appended in front of letter c, if its a different letter or in the wrong order then the card wont be moved.

the code below is the best i can do so far.

a = ['a','c','e','j','h']

b = ['b','d','f','i','g']

def list_a():

    loop = 0
    choice = 0

    while loop == 1:
        print('''Choose from one of the following options:
                    1. Move item from list b to list a
                    2. add item to list a!''')

        choice = int(input("What would you like to do?: "))
        if choice == 1:
            move_item()

        elif choice == 2:
            add_item()
    return choice

    print('List a: ',a)
    print('List b: ',b)




def move_item():
    loop = 0
    choice = 0

    while loop == 1:
        print('''Choose from one of the following options:
                    1. Move item 1
                    2. move item 2
                    3. Move item 3
                    4. move item 4
                    5. Move item 5!''')

        choice = int(input("What would you like to do?: "))
        if choice == 1:
            a.append(b.pop(0))

        elif choice == 2:
            a.append(b.pop(1))

        elif choice == 3:
            a.append(b.pop(2))

        elif choice == 4:
            a.append(b.pop(3))

        elif choice == 5:
            a.append(b.pop())

    return choice

def add_item():
    print()

list_a()
  • 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-31T03:28:14+00:00Added an answer on May 31, 2026 at 3:28 am

    Create a subclass of list and override setitem, insert, and/or whatever else you need to to store your business logic.

    class MyList(list):
      def passes_rules(self, idx, value):
        """ Checks to see if this value can be set to this index """
    
      def __setitem__(self, idx, value):
        if self.passes_rules(idx, value):
          super(MyList, self).__setitem__(idx, value)
    

    Somebody else could probably tell us if setitem is sufficient, or if you need to worry about append and insert, also. Experimentation would work, too, but let me know what you find. 🙂

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

Sidebar

Related Questions

Basicly what I need is to be able to rename an XmlElement (which is
I need to develop an app that is using multithreading. Basicly, I have a
I have a session class that basicly just sets and retrieves session variables, the
I basicly need to load the whole XML file, add a new line with
Basicly, what I need for the program to do is to act a as
I need to be able to access my database, which in it's own isn't
basicly i need my page to respond to left and right arrow keys. so
I am wondering how to take an EditText area that the user can enter
Greetings, I'm in need of a way where I can execute methods on the
I need a Timer that basicaly does something every t seconds. But I want

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.