The list and dictionary object types are two of the most important and often used types in a Python program. Compare the functionalities of those two objects. What are some ways to insert, update, and remove elements from lists and dictionaries? Why would you choose one data type over another? Provide code examples demonstrating the usages of both data types.
Both list and dictionary are linear data types...
lets see first : list
elements are accessed in list through the index..
example:
l = [1,6,4,5]
to access 3rd element we use l[3]
here 3 is index value...of 4
to update in list
just simply use
l[3] =10
now
the list will be
l = [1,6,10,5]
to insert element to list:
to insert at position 3
then l.insert(3,20)
at position 3 inserting 20
list will be
l = [1,6,10,20,5]
to delete element from list :
l.remove(6)
removes the element 6 from list
l = [1,10,20,5]
lets see dictionary:
values...are accesed through keys in dictionaries
example:
d = {'a': 1, 'b': 'a' }
d['a'] will be 1
here keys and values can be any thing char,string,int float...
data can be accessed through any data type...
this is the advantage of dictionary over list...in list data accessed by int data type only..
you want to use strings /chars as ur indexes then use dictionary
updating a value
d['a'] =2
now dictionary
d = {'a': 2, 'b': 'a' }
inserting a value to dictionary:
d['c']=3
adding new item
deleting from dictionary
just use
del d['a']
The list and dictionary object types are two of the most important and often used types...
5. What does this error refer to?Traceback (most recent call last): File "program.py", line 2, in times[2] = 10TypeError: 'tuple' object does not support item assignment * 6. Like most other builtin Python data types, tuples can be compared using the standard comparison operators. True or False? * True False 7. The easiest way to think about sets is that they are like dictionaries without values; that is, the keys in a dictionary are a set. True or False? *...
Questions 1. How to create a comment in python? 2. The way to obtain user input from command line 3. List standard mathematical operators in python and explain them 4. List comparison operators in python 5. Explain while loop. Give example 6. Explain for loop. Give example 7. How to create infinite loop? And how to stop it? 8. Explain a built-in function ‘range’ for ‘for’ loop 9. Explain break statement 10. Explain continue statement 11. Explain pass statement 12....
Python Object oriented programming
Exercise 3 Dictionary Computers are playing an increasing role in education. Write a program that will help an elementary school student to learn English. To simplify the model, the program will first teach numbers from 1 to 10, colors and fruits. It will use a dictionary to store the pairs Spanish-English words. dataTable-uno':one,'dos':'two....' rojo':'red','blue':'Azul... manzana': apple, nara nja:orange. When running your program, it should get a random Spanish word from the dictionary dataTable and then show...
Your task in to design a game of Nim in Python. In this game “Two players take turns removing objects from distinct heaps or piles. On each turn, a player must remove at least one object, and may remove any number of objects provided they all come from the same heap/pile. The goal of the game is to avoid taking the last object.” (Wikipedia) In your implementation of the game, there will be 3 piles of objects. At the start...
Task 1 Draw a flowchart that presents the steps of the algorithm required to perform the task specified. You can draw the flowcharts with a pen/pencil on a piece of paper and scan it for submission. Please ensure that the scanned file and your handwriting are clear and legible. However, it is preferable to draw flowcharts using a drawing software. Here are links to some free drawing tools https://www.draw.io/ www.lucidchart.com http://dia-installer.de/ https://pencil.evolus.vn/ ---------------------------------DON'T NEED THE PYTHON CODE... JUST THE ALGORITHM...
Task 1 Draw a flowchart that presents the steps of the algorithm required to perform the task specified. You can draw the flowcharts with a pen/pencil on a piece of paper and scan it for submission. Please ensure that the scanned file and your handwriting are clear and legible. However, it is preferable to draw flowcharts using a drawing software. Here are links to some free drawing tools https://www.draw.io/ www.lucidchart.com http://dia-installer.de/ https://pencil.evolus.vn/ ---------------------------------DON'T NEED THE PYTHON CODE... JUST THE ALGORITHM...
Deletion of List Elements The del statement removes an element or slice from a list by position. The list method list.remove(item) removes an element from a list by it value (deletes the first occurance of item) For example: a = ['one', 'two', 'three'] del a[1] for s in a: print(s) b = ['a', 'b', 'c', 'd', 'e', 'f', 'a', 'b'] del b[1:5] print(b) b.remove('a') print(b) # Output: ''' one three ['a', 'f', 'a', 'b'] ['f', 'a', 'b'] ''' Your textbook...
I need the report like this (idea) *Sorting Algorithms: A sorting algorithm is an algorithm that puts elements of a list in a certain order. The most-used orders are numerical order and lexicographical order. Efficient sorting is important for optimizing the use of other algorithms (such as search and merge algorithms) which require input data to be in sorted lists; it is also often useful for canonical zing data and for producing human-readable output. More formally, the output must satisfy...
6. With respect to database systems, which of the following statement(s) is (are) true? a. The physical view of data is how people conceptually organize and understand the relationships among data items. b. The DML builds the data dictionary, creates the database, describes logical views for each user, and specifies security constraints. c. A record layout shows the items stored in a file, including the type of data stored and both the order and length of the data fields. d....
Using Python.
3) Create a single-linked list (StudentList) where the data in the link is an object of type pointer to Student as defined below. Note that you need to store and pass a pointer of type Student so that you do not create duplicate objects. Test your list with the provided program. You will find example code for a single-linked list of integers in Moodle that you can base your solution on. For your find methods, you can either...