Question

In: Computer Science

Create a program (or set of programs) which accomplish the following for each complex data type...

Create a program (or set of programs) which accomplish the following for each complex data type (list,tuple,set,frozenset, dictionary):

  • create the item with at least 4 elements
  • Append an element
  • Remove an element
  • Insert an element in the middle somewhere
  • Append another array of the same data type
  • Append another array of a different data type (for example, if you have a dictionary, append a set or tuples

And do the following:

  • Output the results after each step.
  • Report and explain any errors (if a line of code generates an error, comment it out along with a comment on what the error was and your reasons for that error)
  • Create a range of negative numbers
  • Create a range of positive even numbers
  • Insert a range into each data type that would allow it

Turn in:

  • All source code
  • Execution of your program(s)
  • Explanation of each error you ran into

PYTHON.

Solutions

Expert Solution

List

list.append() - used to insert element and another data structure at the end of list.

list.insert() - used to insert element at the particular index.

list.extend() - iterate over the list or string which we want to insert in list and insert it into the list.

list.remove() - remove that element from the list.

list.clear() - remove all the element from the list.

Here are the program in jupyter notebook :

Tuple

Tuple is immutable that means we cannot modify element in tuples.

Tuple elements are unchanged.

insert, remove and insert at particular index does work with tuple data structure.

Set

Set contains only unique element.

Set are unordered so we cannot add element at any index.

Set are written with {} curly bracket and set() function.

programs are given below for better understanding :

FrozenSet

Frozenset are the immutable version of set.

we cannot change, modify and remove element from frozenset. so any function like insert, delete and remove will not work with frozenset.

programs are below for better understanding :

Dictionary in python

Dictionary contains key value pair

Dictionary are unordered so insert at particular index is not possible.

Dictionary contains following functions like pop - to remove element, len - to find the length , clear - to remove all element, get - to get the particular function

programs are given below for better understanding :

2nd Part of Question

1. to create a range of negative numbers :

for creating range of negative number we use range function:

2. for creating positive even number we again use range function:

3. Insert range of element in data structure

Here I am showing only list and set because tuple and frozenset are immutable.

  


Related Solutions

Create a program (or set of programs) which accomplish the following for each complex data type...
Create a program (or set of programs) which accomplish the following for each complex data type (list,tuple,set,frozenset, dictionary): create the item with at least 4 elements Append an element Remove an element Insert an element in the middle somewhere Append another array of the same data type Append another array of a different data type (for example, if you have a dictionary, append a set or tuples And do the following: Output the results after each step. Report and explain...
In C++, use SML programs to accomplish each of the following tasks: a) Use a sentinel-controlled...
In C++, use SML programs to accomplish each of the following tasks: a) Use a sentinel-controlled loop to read positive numbers and compute and display their sum. Terminate input when a negative number is entered. b) Use a counter-controlled loop to read seven numbers, some positive and some negative, and compute and display their average. c) Read a series of numbers, and determine and display the largest number. The first number read indicates how many numbers should be processed. For...
In this program, you'll create a program that utilizes an enumerated data type to manipulate the...
In this program, you'll create a program that utilizes an enumerated data type to manipulate the array.   Here are the requirements: Write a program that contains an enumerated data type named Letters.    In the declaration, include the following three enumerators: ALPHA, BETA, DELTA. Then, create an array of integers three elements long. The array should be initialized to 0 using a 1-element initialization list. Instead of using integers as subscripts, use the enumerators from your enumerated data type to assign...
Use of an Irrevocable Life Insurance Trust can accomplish which of the following? A. Create a...
Use of an Irrevocable Life Insurance Trust can accomplish which of the following? A. Create a vehicle to avoid Generation Skipping Transfer Tax B. Make proceeds available to the surviving spouse C. Ensure that proceeds will be included in the probate and gross estate of grantor D. Shelters cash contributed for premiums from taxation up to the annual exclusion amount
Create programs in Visual Basic which perform each of the following: Explain the different design choices...
Create programs in Visual Basic which perform each of the following: Explain the different design choices (syntax) for option in each language Document the programs using Flowcharts Each programs source code must be included – label each with the language used a) Nested two-way selection statements b) Multiple-way selection statement c) Iterative Statements – Counter controlled and Logic controlled d) After the Counter Controlled Iterative successfully completes – Display “This was a success” on the screen.
Create programs in Visual Basic which perform each of the following: Explain the different design choices...
Create programs in Visual Basic which perform each of the following: Explain the different design choices (syntax) for option in each language Document the programs using Flowcharts Each programs source code must be included – label each with the language used a) Nested two-way selection statements b) Multiple-way selection statement c) Iterative Statements – Counter controlled and Logic controlled d) After the Counter Controlled Iterative successfully completes – Display “This was a success” on the screen.
Using the following lines of data, create a temporary SAS data set called ThreeDates. Each line...
Using the following lines of data, create a temporary SAS data set called ThreeDates. Each line of data contains three dates, the first two in the form mm/dd/yyyy descenders and the last in the form ddmmmyyyy. Name the three date variables Date1, Date2, and Date3. Format all three using the MMDDYY10. format. Include in your data set the number of years from Date1 to Date2 (Year12) and the number of years from Date2 to Date3 (Year23). Round these values to...
The following program will be written in JAVA. Create a class called complex performing arithmetic with...
The following program will be written in JAVA. Create a class called complex performing arithmetic with complex numbers. Write a program to test your class.                         Complex numbers have the form:                         realPart + imaginaryPart * i                                               ___                         Where i is sqrt(-1)                                                 Use double variables to represent data of the class. Provide a constructor that enables an object of this class to be initialized when it is declared. The constructor should contain default values in...
Create comprehensive audit programs for the Sales and Receivables So each audit program would include the...
Create comprehensive audit programs for the Sales and Receivables So each audit program would include the following components: Audit steps for tests of controls, balances, transactions, analytical procedures, etc. as well as other considerations such as sample size and sample methodology.
Write program logic or pseudocode to create 3 small programs that do the following: The first...
Write program logic or pseudocode to create 3 small programs that do the following: The first should compute the sum of 2 given integers. The second should multiply the 2 integers. The third should triple the sum of the 2 integers.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT