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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:28:33+00:00 2026-06-17T12:28:33+00:00

I have a program that, simplified, looks like this: def listAssign(lst,index,item): Assigns item item

  • 0

I have a program that, simplified, looks like this:

def listAssign(lst,index,item):
    """Assigns item item to list lst at index index, returns modified list."""
    lst[index] = item
    return lst

def listInsert(lst,index,item):
    """Inserts item item to list lst at index index, returns modified list."""
    lst.insert(index.item)
    return lst

# ...

def listSurgery(lst,indices,f,*extraArgs):
    """Performs operation f on list lst at depth at indices indices, returns modified list."""
    parent = lst
    for index in indices[:-1]:
        parent = parent[index]
    parent = f(parent,indices[-1],*extraArgs)
    return listSurgery(lst,indices[:-1],listAssign,parent)

# ...

def parseStringToList(s):
    """Takes in a user-input string, and converts it into a list to be passed into parseListToExpr."""
    for c in s[:]: # Removes extra spaces from beginning of string
        if c == ' ':
            s = s[1:]
        else:
            break
    for c in s[::-1]: # Removes spaces from end of string
        if c == ' ':
            s = s[:-1]
        else:
            break
    l = [] # List to build from string; built by serially appending stuff as it comes up
    b = True # Bool for whether the parser is experiencing spaces (supposed to be True if last character processed was a space)
    t = False # Bool for whether the parser is experiencing a string of non-alphanumeric characters (supposed to be True if last character was a non-alphanumeric character)
    lvl = 0 # Keeps track of depth at which operations are supposed to be occurring
    for c in s:
        if c == ' ': # If the character is a space, do nothing, but make sure that it's documented that the last character processed was a space
            b = True
        elif c == '(' or c == '[': # If the character is an opening parenthesis, add a new level of depth to the list, by appending another list to the lowest level and incrementing lvl
            l = listSurgery(l,[-1]*(lvl+1),listInsert,[])
            lvl += 1
            if c == '[': # ] (left here for overzealous parsers) If the bracket is square, also append a comma as the first element of the appended list
                l = listSurgery(l,[-1]*(lvl+1),listInsert,',')
        elif c == ')' or c == ']': # If it's a closing parenthesis, make it stop paying attention to the list it's working on
            lvl -= 1
        elif c == ',': # If it's a comma, then append it to the list as a separate element and start a new string to append characters to
            l = listSurgery(l,[-1]*(lvl+1),lambda x,y,z:listAssign(x,y,x[y]+z),[',',''])
        elif not c.alnum(): # If it's non-alphanumeric and not any of the above, then append it to string that it's working on if it's a non-alphanumeric string
            if not t: # If the string that it's working on isn't non-alphanumeric, then finish working on that string and append a new string to work on
                l = listSurgery(l,[-1]*(lvl+1),listInsert,'')
            l = listSurgery(l,[-1]*(lvl+1),lambda x,y,z:listAssign(x,y,x[y]+z),c)
            t = True
        else: # If the character is alphanumeric, append it to the string it's working on
            assert c.isalnum()
            if b or t: # If the string it's working on isn't alphanumeric or doesn't exist, append a new string
                l = listSurgery(l,[-1]*(lvl+1),listInsert,'')
                b, t = False, False
            l = listSurgery(l,[-1]*(lvl+1),lambda x,y,z:listAssign(x,y,x[y]+z),c)
    return l

# ...

cmds = {
        'help':"List the available functions.",
        'quit':"Quit this application.",
        'exit':"Exit this application (exactly the same thing)."
        }

print "MAT (Michael's Analysis Tool), version 0.0.0"

op = '' # Declare string to use for input
while op != 'exit' and op != 'quit': # Keep a REPL unless the user types "exit" or "quit", in which case exit
    op = raw_input("> ")
    if op == 'help':
        print "The commands available in addition to free evaluation are:"
        for item in cmds:
            print ' ', item + ":", cmds[item]
    elif op == 'quit' or 'exit':
        pass
    else:
        print str(parseStringToList(op))

When I use help, quit, or exit as a command, it comes out fine. But when I give it any other kind of input like 1 + 1 = 2 (which should elicit ['1','+','1','=','2']) or This is a sentence. (which should elicit ['This','is','a','sentence','.'], it doesn’t print anything, just asks for more input. (That is, it’s functionally equivalent to the last line of this program getting replaced with continue.) And I don’t understand why. parseStringToList is defined in a very straightforward manner. It should at least return [], the original value of the variable it returns. But instead it doesn’t print anything. Why? (I’ll try more thorough debugging tomorrow, but so far it’s eluded my efforts.)

  • 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-17T12:28:34+00:00Added an answer on June 17, 2026 at 12:28 pm

    You need to change this:

    elif op == 'quit' or 'exit':
    

    to this

    elif op == 'quit' or op == 'exit':
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question contains java and ruby. I have a java program that I make
This is a bit hypothetical and grossly simplified but... Assume a program that will
I have program that requires Python 3, but I develop Django and it uses
I have program that has a variable that should never change. However, somehow, it
I have program that runs fast enough. I want to see the number of
I have a program that gets a JSON from the server using getJSON and
I have a program that saves an image in a local directory and then
I have a program that reads from a file that grabs 4 bytes from
I have a program that encrypts files, but adds the extension .safe to the
I have a program that I want to distribute, without giving the source code

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.