Question

In: Computer Science

I am stuck on the following problem please and it has to be in python! 1)...

I am stuck on the following problem please and it has to be in python!

1) Initially, create a list of the following elements and assign the list to a variable "thing".

"Mercy", "NYU", "SUNY", "CUNY"

2) print the list above

3) add your last name to the list

4) print the list

5) add the following elements as a nested list to the list:

"iPhone", "Android"

6) print the list

7) add the following list to the end of the list as elements:

["MIT", "CMU"]

8) print the list

9) add the following nested list to the third position of the list thing:

[30, 40+1]

10) print the list

11) delete "SUNY" from the list. # revised this question on 9/24 8:41pm!

12) print the list

13) add "Mercy" to the second last in the list (so "Mercy" should be in between "MIT" and "CMU"):

14) print the list

15) count "Mercy" in the list and print.

16) print the number of the top-level elements in the list.

17) In Step 10 above, explain why 40+1 is entered 41 to the list.


Challenge) Can we remove an element from a nested list? If yes, explain how in plain text. If not, explain why not

Challenge) Can we count each every element in a list, which may contain nested lists? If yes, explain how in plain text. If not, explain why not

Solutions

Expert Solution

That's a lot of questions.

Howwver, I have solved all of them.

please follow the beloe steps.

SOURCE CODE:

*Please follow the comments to better understand the code.

**Please look at the Screenshot below and use this code to copy-paste.

***The code in the below screenshot is neatly indented for better understanding.

# 1. create initial list
thing = ["Mercy", "NYU", "SUNY", "CUNY"]

# 2. print the list
print(thing)

# 3. add your name to the list
# Replace XYZ with your name
thing.append('XYZ')

# 4. print the list again
print(thing)

# 5. add elements as nested list
thing.append(["iPhone", "Android"])

# 6. print the list again
print(thing)

# 7. add list to end
thing.append(["MIT", "CMU"])

# 8. print the list again
print(thing)

# 9. add list at 3rd position
thing.insert(3, [30, 40 + 1])

# 10. print the list
print(thing)
# 11. delete SUNY from list
thing.remove("SUNY")
# 12. print the list
print(thing)

# 13. add Mercy to the second last in list
thing.insert(-2, "Mercy")

# 14. print the list
print(thing)

# 15.count Mercy and print
print(thing.count("Mercy"))

# 16. Number of top level elements
print(len(thing))
# 17
# Here 40+1 = 41 this operation will be performed and result of 41 will be added instead of 40+1

# Challenge1: Yes, we can remove elements in nested list.
# Ex: x=[ [1,2], [4,5] ]
# To remove 5, we use delx[1][1]

# Challenge2: Yes, we can do it using NESTED LOOPS

===============

SCREENSHOTS:


Related Solutions

I am stuck on this problem and I am not sure what the solution is. In...
I am stuck on this problem and I am not sure what the solution is. In C Write item.h and item.c. In item.h, typedef a struct (of type t_item) which contains the following information: t_item: char name[MAX_ITEM_NAME_STRING]; char description[MAX_ITEM_DESCRIPTION_STRING]; Make sure that MAX_ITEM_NAME_STRING and MAX_ITEM_DESCRIPTION_STRING are defined with suitable sizes in your item.h. Typical values are, 25 and 80, respectively. Add the following interface definition to item.h: int item_load_items(t_item items[], int max_items, char *filename); Returns the number of objects loaded...
I am stuck on the following review problem on confidence intervals. Could you please guide me...
I am stuck on the following review problem on confidence intervals. Could you please guide me on how to approach this type of problem? A bakery does not keep track of the number of chocolate chips they put in their cookies. The number of chocolate chips is normally distributed with mean µ and variance σ2 = 25, where µ is unknown. A customer buys a dozen of these cookies, and obtains the simple random sample 31, 23, 42, 44, 28,...
I am stuck on the following review problem on confidence intervals. Could you please guide me...
I am stuck on the following review problem on confidence intervals. Could you please guide me on how to approach this type of problem? A bakery does not keep track of the number of chocolate chips they put in their cookies. The number of chocolate chips is normally distributed with mean µ and variance σ2 = 25, where µ is unknown. A customer buys a dozen of these cookies, and obtains the simple random sample 31, 23, 42, 44, 28,...
Hi! I am in an intro level Finance course and I am stuck on this problem....
Hi! I am in an intro level Finance course and I am stuck on this problem. Any help would be greatly appreciated. I am deciding on opening a restaurant. I was able to scrape together some capital from friends and family, but I must pay them back in 4 years at 12% per annum. I figure that it will cost me $165,000 to start up with rent, deposits, equipment, salaries, chicken, basil, rice, etc. for the first year, but I...
Java ArrayList Parking Ticket Simulator, Hello I am stuck on this problem where I am asked...
Java ArrayList Parking Ticket Simulator, Hello I am stuck on this problem where I am asked to calculate the sum of all fines in the policeOfficer class from the arraylist i created. I modified the issueParking ticket method which i bolded at the very end to add each issued Parking ticket to the arrayList, i think thats the right way? if not please let me know. What I dont understand how to do is access the fineAmountInCAD from the arrayList...
This is a question for my problem-solving class. I am really stuck and I can't see...
This is a question for my problem-solving class. I am really stuck and I can't see much of a pattern so I would appreciate if someone could draw out for each thief and explain the pattern to get the answer for 40 thieves! Question: Forty thieves, all different ages, steal a huge pile of identical gold coins and must decide how to divide them up. They settle on the following procedure. The youngest divides the coins among the thieves however...
Hello, I am stuck on this problem....... A histogram of height measurements among middle students would...
Hello, I am stuck on this problem....... A histogram of height measurements among middle students would most likely be: This was a homework question I am confused because there is no data for how many kids or how tall they were. I am taking a guess thinking that the kids are would be normally distributed? Am I correct? Could you please solve? Thank you normally distributed orthogonal skewed left skewed right
I am stuck on this Java problem: Create an Animal class with: Attributes Age Rabies Vaccination...
I am stuck on this Java problem: Create an Animal class with: Attributes Age Rabies Vaccination Status Name Owner Name A constructor to set values Getters and Setters for all private attributes A toString method that gives the data of all attributes Create a Dog Class Attributes Distemper Vaccination Status A constructor to set values in sub class A constructor to set values in sub and super class Getters and Setters for private attributes A toString method that overrides the...
I was stuck on the following review problem on hypothesis testing. Could you please guide me...
I was stuck on the following review problem on hypothesis testing. Could you please guide me on how to approach this type of problem? Stacy, a professional soccer player, had a field goal percentage (i.e., probability of making a shot) of p0 = 60% before needing to take a season off to recover from an injury. (a) Since returning to the game from injury, Stacy has made 13 out of n = 20 shots. Is Stacy's new, post-injury field goal...
I was stuck on the following review problem on hypothesis testing. Could you please guide me...
I was stuck on the following review problem on hypothesis testing. Could you please guide me on how to approach this type of problem? The following review problem is on hypothesis testing. Freshmen tend to gain 15 pounds during their first year in college. However, they try to improve their health during their sophomore year. Let X denote the weight loss of sophomores after taking an intensive year-long PE class. Assume that X is normally distributed with unknown mean µ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT