Home » Python, using nested lists (list of lists) from user input [closed]

Python, using nested lists (list of lists) from user input [closed]


So if I’m understanding correctly, the “Lists of List” comment pertains to nested Lists, The code you have is close to what’s needed.
I believe this is what you need.

print("Enter First name, last name and Student ID number. Then press 0 to continue")

userFirst = str(input("Enter First Here:"))
userLast = str(input("Enter Last Name:"))
userStudent = int(input("Enter Student ID number:"))
userInfo = input("Enter more details or pres 0 to enter search mode")

while userInfo != "0":
    userInfo=input("Enter more details")
        print("Search Mode")

###Changed SearchMode to be nested list with each list Holding the input values from [ [UserFirst],[userLast],[userStuden] ]
searchMode = [[],[],[]]
    ### Append userFirst to the first Indexed List
    ### Append userLast to the second Indexed List
    ### Append userStudent to the third Indexed List

userSearch = int(input("Enter Student ID"))

### Since we know that we need to search by The Student Id we Take the InitialList and add the index of our desired Nested List; In this Case it's the 3rd nested
### Then we take the values from the nested List and look for the inputted value and obtain the record corresponding index
userSearch = searchMode[2][userStudent-1]

Let me know if this doesn’t give you the results you need and I’ll try working on it some more

For the fun of it, I recreated the process to be called as a function.

def SearchRequest():
    ### This Will Hold our Input Data
    SearchData = [[],[],[],[]]

    ### This Will Run The Question Prompts We Want Filled
    def promptQuestions():

        # Get User First Name
        def userFirst():
            return SearchData[0].append(str(input('Enter First Name Here: ')))

        # Get User Last Name
        def userLast():
            return SearchData[1].append(str(input('Enter Last Name Here: ')))
        # Get User Student ID
        def userStudent():
            return SearchData[2].append(int(input('Enter Student ID Number: ')))

        # Ask If They Want to Add Additional Info; Entering 0 Will Exit The Asking Phase
        # Once Completed We Will Start the UserId Lookup Phase
        def userInfo():
            #Beginning Prompt
            userInfo = input('Enter More Details Or Press 0 to Enter Search Mode')
            #List We'll Be Using To Hold Inputs
            output = []
            #Append First input To our Output List

            while userInfo != "0":
                #If 0 Was Not Entered: Ask To Enter More Details
                userInfo=input('Enter More Details: ')
                #Append Details To Our Output List
                print('Entering Search Mode')
                #Append Result List To Our Main Search Data

        # Ending Of Prompt Questions
        def runQuestions():
            """This will be used to hold the order of execution"""
            return SearchData
        return runQuestions()

        #Create a Search Mode Allowing User To Lookup ID
    def SearchMode():
            #Gets Input ID to LookUP
        def SearchStudentID():
            return int(input('Enter Student ID: '))
        #Returns the matching ID as long as the ID is the same as the index Number
        return SearchData[2][SearchStudentID()-1]

    # Final Layer to Our Searching Process
    def runSearchProcess():

        #Begins Main Prompt Phase

        #Once Everything is completed, Return the search Modes Result
        return SearchMode()
    #Ending Of Search Request
    return runSearchProcess()


Related Solutions

What are the available Signals in Java

Eventually I brute forced the single to 5 character length signals and got these: BREAK (21) SEGV (11) ILL (4) FPE (8) TERM (15) ABRT (22) INT (2) The code: Set<String> signals = new HashSet<>(); String currentSignalStr; for (char i = 'A'; i <=...

Understanding unique keys for array children in React.js

You should add a key to each child as well as each element inside children. This way React can handle the minimal DOM change. In your code, each <TableRowItem key={item.id} data={item} columns={columnNames}/> is trying to render some children inside them...

most efficient AABB vs Ray collision algorithms

Andrew Woo, who along with John Amanatides developed the raymarching algorithm (DDA) used ubiquitously in raytracers, wrote "Fast Ray-Box Intersection" (alternative source here) which was published in Graphics Gems, 1990, pp. 395-396. Rather than being built...

What is the difference between #!/bin/sh and #!/bin/bash?

bash and sh are two different shells. Basically bash is sh, with more features and better syntax. Most commands work the same, but they are different. Having said that, you should realize /bin/sh on most systems will be a symbolic link and will not invoke sh....

How to pass password to mysql command line

The mysql client utility can take a password on the command line with either the -p or --password= options. If you use -p, there must not be any blank space after the option letter: $ mysql -pmypassword I prefer the long options in scripts as they are...

how to leave a gap in select list from left [closed]

Maybe you were after something like: <select style="padding: 0 0 0 10px"> <option>Male</option> <option>female</option> <option>other</option> </select> jsFiddle example here. Is that what you wanted? Edit: After...

How to use multiple condition in one foreach loop?

Use two loops: foreach ($products as $product) { foreach ($categories as $category) { // using $product and $category } } I had the same question today as the OP. I figured I can split up the problem by first merging the two arrays and then performing the...

Why do Primitive Data Types have a Fixed Size?

As low-level programming languages, the designs of C and C++ closely follow what common hardware is capable of. The primitive building blocks (fundamental types) correspond to entities that common CPUs natively support. CPUs typically can handle bytes and words...

how do i count the words in a string list

Shouldn't it be string[] words = s.Split(' '); Even if we say your word is s.Split(' '); then it should be string[] words = word not string[]=word And to count how much words are in that array just do int howManyWords = words.Length; Also if you want to go...

Data from text file to dataframe

Here you go! It's really fast. For a file with ~11 million lines (made by copying and pasting your sample file over and over again), it took about 22 seconds on my machine, and produced a dataframe with 2.2 million rows. Note: I wasn't sure quite how to handle...

Unexpected output when creating a List of Lists in Java

You are adding all the integers to the same inner list (the one that you create at the start of your method with the statement List<Integer> l1 = new ArrayList<Integer>();). You should create a new List before adding elements to it: for(int i=1;...

how to calculation cost time [closed]

I think I understand what you're asking. You just want to have a new dataframe that calculates the time difference between the three different entries for each unique order id? So, I start by creating the dataframe: data = [...

how to disable button on change using jquery

you can do this as am assuming a image and am checking the resolutions and then i disable or enable the button as per requirements and also am clearing selected image so user can't upload the wrong format . <script> var _URL = window.URL ||...

Detect and uninstall antivirus

You could try the following, from https://community.spiceworks.com/scripts/show/3161-detect-and-remove-software-powershell: ################################################ # Powershell Detect and Remove software script # # # # V1.0 - Gav #...

return statement in c ??? why this function always returning 20?

You have a problem in your code. Change scanf("%d",arr[i]); To scanf("%d",&arr[i]); This is done because scanf expects an argument of type int* but you provide argument arr[i] which is of type int. Also add a check that ends the program if user inputs a...

How to add Bootstrap? [closed]

By adding the CDN <html> <head> <title>Cube</title> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script> <!-- Latest compiled and minified CSS --> <link rel="stylesheet"...