Question

In: Computer Science

Describe two situations in which you would use a list; two situations in which you would...

Describe two situations in which you would use a list; two situations in which you would use a tuple, and two situations in which you would use a dictionary. Also do some research to learn about data structure sets, describe when and how to use sets.

Solutions

Expert Solution

# List :

@ A list is an ordered set of data/element  that can be easily changed .

@ List is a collection of elements  of different data types.

@ A list object contains one or more elements ,it may or may not be  of the same type, which are separated by comma(,) and enclosed in square brackets [].

@ List items are refered by the  index number. we can use  index operator [ ] to access an item in a list.

@ List allows duplicate elements .

@ Lists are like arrays .

Examples :

1> List can have similary types of Elements like NAMES

names=["john", "Bob", "Steve", "Maya"]

2> List can also contain elements of different types like a STUDENT ID .

Item=[1, "John", "Computer", 75, class1]

# Tuple :

@ A tuple is an ordered set of data that cannot be changed . Tuple  allows duplicate elements .

@ Tuples cannot be modified after it is created. which means Tuples are  "immutable" .

@ Tuples are created by a sequence of values separated by ‘comma’

it can be with or without the use of () .

@ Tuples may  contain any number of data/elements and of any datatype .

Examples :

1> Tuples can be used to store collection of fruits

fruits=("apple", "pear", "banana", "cherry")

2>Tuples can also store details of product .

Item=(100, "mango ", "habus", 15.50, good)

# Dictionary :

@ Dictionaries are  group of data/elements with  key and value pairs 'key':'value' .

@ Dictionary  is an unordered collection of data values .

@ It is used to store data values like a map .

@ key-value pair in a Dictionary is always separated by a colon : .

@ Dictionary don't allow duplicate elements.

Examples :

1> Point in the plane

points={"p1":(30,30), "p2":(60,60)}

1> Dictionary can also store countary and capital value pairs


countary={"USA":"New York", "UAE":"Abu-dhabi", "India":"New Delhi"}

# Set :

@ Set is an unordered collection of data type.

@ Set don't allows  duplicate elements/data .

@ A set object may contains one or more items, not necessarily of the same type. which are always separated by comma (,) and enclosed in curly brackets {}.

Examples :

1>Set can be used to store collection of numbers.

Input :

>>> Z1={1, 2, 2, 3, 4, 5}
>>> Z1

output: {1, 2, 3, 4, 5}

1>Set can be used to store ID of an employee.

>>> ID={1, "Bob", 101}


Related Solutions

Describe situations in which you might use a certified check, cashier’s check, or money order.
Describe situations in which you might use a certified check, cashier’s check, or money order.
List three variables, and how they are measured, for which you would use the mode as...
List three variables, and how they are measured, for which you would use the mode as the most appropriate measure of central tendency.
In which of the following situations would it be appropriate to use a paired t-test to...
In which of the following situations would it be appropriate to use a paired t-test to analyze the data? Check all that apply. A researcher was interested in the differences in attitudes towards saving money and eliminating debt between couples who are engaged to be married. As part of a premarital counseling program, 45 engaged couples filled out a survey that assessed their attitudes towards financial matters such as their priorities for saving money and eliminating debt. The researcher compared...
List and describe three real life situations in which is possible to experience centripetal force.
List and describe three real life situations in which is possible to experience centripetal force.
Discuss the reasons and situations in which researchers would want to use linear regression. How would...
Discuss the reasons and situations in which researchers would want to use linear regression. How would a researcher know whether linear regression would be the appropriate statistical technique to use? What are some of the benefits of fitting the relationship between two variables to an equation for a straight line? Describe the error in the conclusion. Given: There is a linear correlation between the number of cigarettes smoked and the pulse rate. As the number of cigarettes increases the pulse...
Discuss the reasons and situations in which researchers would want to use linear regression. How would...
Discuss the reasons and situations in which researchers would want to use linear regression. How would a researcher know whether linear regression would be the appropriate statistical technique to use? What are some of the benefits of fitting the relationship between two variables to an equation for a straight line? Describe the error in the conclusion. Given: There is a linear correlation between the number of cigarettes smoked and the pulse rate. As the number of cigarettes increases the pulse...
26) In which of the following situations would you prefer to be the lender?
SCENARIO 4. Notation: C = currency; D = demand deposits; T = time deposits; & S = saving deposits. Suppose M1 = C + D; M2 = C + D + T; M3 = C + D + T + S. Suppose also that C = .05D; T = .4D; & S = .3D. The Fed imposes the following reserve requirements: rd = .2; rt = .3; rs = .15. Banks keep the following excess reserve ratios: ed = .05;...
Describe some sampling situations in which a sampler which takes a stratified sample would be necessary.
Describe some sampling situations in which a sampler which takes a stratified sample would be necessary.
The following problem situations occurred in a manufacturing company. List a question you would ask to...
The following problem situations occurred in a manufacturing company. List a question you would ask to understand the problem. Hint: "Why did this happen?" is not an adequate response. Be sure to identify the problem as well as the question you ask. Customer complaints about product quality have increased.
Which of the following measure would you use to describe the “spread” or degree of dispersion...
Which of the following measure would you use to describe the “spread” or degree of dispersion of the distribution of a random variable? A. skewness B. standard deviation C. mean D. kurtosis
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT