Question

Search the Web for an example of list in Python code, share it, and post the...

Search the Web for an example of list in Python code, share it, and post the link for the site.


Describe how it works in English as an algorithm, which is a sequence of simple steps.


Why do we use lists in Python? How do they differ from a dictionary?


0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: As per Chegg Policy we can't paste external links in answer section. So I will be giving my own example and algorithm and explanation.

Python List

List is a 1 of collection in python out of 4(List,Tuple,Set,Dictionary) . List is ordered and the value of list can be changed. Value in a list is referred by their index position. Index starts from 0(zero). List can hold duplicate values or elements.

Example

#declaring list of integers
mylist = [1, 2, 3,4,5,6,7,8,9]

#printing 3rd element from mylist
print(mylist[2])
#printing total length of mylist or total number of elements in mylist
print(len(mylist))
#checking whether value 9 is present in mylist
if 9 in mylist:
print("Number is Present")
else:
print("Number is Not Present")

#adding element 10 to mylist using append method
mylist.append(10)
print(mylist)

Output:

3                                                                                                                             

9                                                                                                                             

Number is Present                                                                                                             

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]  

Algorithm

  • The above program first print 3 which is the 3rd element in list we access this by index 2(mylist[2]) ,
  • then it prints 9 total number of elements in mylist using len (length method in python)
  • Then we are checking whether 9 is present in mylist or not and printing corresponding values.
  • last we add 10 to mylist using python built in method append and print all elements of mylist

Usage of List

List is mainly used when we doesn't need random access of data & is used when data are simple collection and are easily accessed through iteration instead of lookup.Lists are mainly used when we need slicing of data values.

Difference between List and Dictionary

  • List is ordered but Dictionary is unordered
  • List allows duplicate elements but Dictionary doesn't allow duplicates
  • List uses index values starting from 0 to access elemets but dictionary uses key to access values
  • List is declared as elements enclosed in square bracket but in dictionary values are enclosed in braces as key value pairs
  • List allows slicing (printing few parts of list) but dictionary doesn't allow slicing
Add a comment
Know the answer?
Add Answer to:
Search the Web for an example of list in Python code, share it, and post the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Search the Web for an example of a structured program in Python. Share the link to...

    Search the Web for an example of a structured program in Python. Share the link to the example and describe how it works. Why do we use structured programming in Python?

  • Turn in an algorithm (not Python code) that describes how a speech recognizer or a web...

    Turn in an algorithm (not Python code) that describes how a speech recognizer or a web crawler (spider) works. This algorithm is a sequence of steps that a computer would follow in order to generate an output. These instructions would not be followed by a human but rather by a machine. For instance, do not state things like open a web browser and type in the subject that you are searching for.This algorithm needs to be saved as a .doc,...

  • Find an example of a Python program on the Web that illustrates the program’s decisions using...

    Find an example of a Python program on the Web that illustrates the program’s decisions using if and while statements. Provide a link for the source. What is happening in your programming example? Describe it in English as an algorithm. After the else statement executes, which program statement executes next in your example?

  • Hi I'm trying to write a code for a web server in python with flask. This...

    Hi I'm trying to write a code for a web server in python with flask. This is what I have so far from flask import Flask app = Flask(__name__) @app.route('/') #first endpoint i.e. "http://localhost/" def index(): return 'hello' #return data in string if __name__ == '__main__': app.run(debug=True) After running the code, I'm given a address to the web with the text hello. The problem is that this only works with my computer that is running the code. If I try...

  • List Python

    A car park management system uses a list to represent which spaces in a car park are currently occupied and which are currently unoccupied. An empty space is represented by a 0 and a full space by a 1. Then the state of the car park would be represented by the following list: [1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0] The designers of the car park management system require a program that will accept a list such as the one above (although of course the length will not always be 11) and calculate what percentage of the spaces are currently occupied, rounded to the nearest percent. In the example above 7 spaces are occupied and there are 11 altogether, so the percentage occupied is: (7 / 11) x 100 = 63.63… = 64% to the nearest whole number. i.What are the admissible inputs of the problem? ii.What is the output of this problem? iii.Write three tests for this problem. The inputs should be different from the example given in the scenario description above. At least one of your tests must be a borderline case. Present the tests in a table, with a column for each input and output, and an extra column with a brief explanation of why you selected each test iv.Decompose the problem into sub-problems. Use the > notation and state in brackets the type of the problem and of each sub-problem v. Choose the patterns for the subproblem types you identified, instantiate the patterns into an algorithm, and translate the algorithm into code.This part of the question involves writing Python code. Write your code in this file and then submit the completed code file as part of the answer to this part of the question. Note: Although Python has a built-in function to find the sum of a list, please do not use it to compute how many 1s there are in the list. We want you to write your own code , because the purpose of this question is to practice following the problem solving approach described there, which will equip you to solve problems in other cases for which there is no built-in Python function. A Python program which is not preceded by a corresponding decomposition will gain at most half marks. Again, the reason for this is that we want you to follow a systematic problem-solving approach and not dive straight into code. Please therefore make sure that you have supplied an answer to iv. If you find it difficult to get the decomposition quite right at first there is no reason why you cannot review it when you have written the code. The main thing is to have a clear idea of what the solution needs to do (the decomposition) that ties in correctly with how it does it (the program). Make sure you use appropriate variable names and comments and that you have tested your code with the inputs of your test table. (Keep each of your test inputs in your code, but precede all of the test inputs, except for one, with the # symbol. Recall that # signals a comment, which is ignored by the Python interpreter.)

  • ORIGINAL POST, NO PLAGIARISM. DO NOT POST PREVIOUSLY SUBMITTED ANSWER. PLEASE INCLUDE REFERENCES Share an example...

    ORIGINAL POST, NO PLAGIARISM. DO NOT POST PREVIOUSLY SUBMITTED ANSWER. PLEASE INCLUDE REFERENCES Share an example of a brand that you think uses social media marketing very effectively. What techniques do they use and what makes them so effective? Is it important for brands to listen to social media chatter? Why or why not? Can this “chatter” add value to your IMC program? If yes, describe how it adds value, and if no, explain why not.  

  • Write code in python for following Use queue to implement it Implement a decryption method String...

    Write code in python for following Use queue to implement it Implement a decryption method String decrpt(String s) to decrypt a number sequence (stored in a string s). The decryption algorithm works as follows: Delete the first element of the sequence Move the first element of the sequence to the end Delete the first element of the sequence Move the first element of the sequence to the end …. This process keeps running until all element in the sequence has...

  • Project 6: Create a double-linked list and traverse the list forward and backward. Document the code...

    Project 6: Create a double-linked list and traverse the list forward and backward. Document the code and make sure to include an explanation of how the link list works. If the student adds additional features, he/she should document that as well. In testing the list, show what happens in the case of the NULL list. Show why this type list is easier to search than a single-linked list.

  • Create a new program in Mu and save it as ps4.5.2.py and take the code below...

    Create a new program in Mu and save it as ps4.5.2.py and take the code below and fix it as indicated in the comments: # Do not change the line of code below. It's at the top of # the file to ensure that it runs before any of your code. # You will be able to access french_dict from inside your # function. french_dict = {"me": "moi", "hello": "bonjour", "goodbye": "au revoir", "cat": "chat", "dog": "chien", "and": "et"} #...

  • Please code in Python. Python version 3.7.1 These are the hints and remarks for this question....

    Please code in Python. Python version 3.7.1 These are the hints and remarks for this question. In the following sequence, each number (except the first two) is the sum of the previous two number: 0, 1, 1, 2, 3, 5, 8, 13, This sequence is known as the Fibonacci sequence. Given the positive integer n create a list consisting of the portion of the Fibonacci sequence less than or equal to n. For example, if n is 6, then the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT