Question

In: Computer Science

Given a list of items, write a program that generates a list of lists of the...

Given a list of items, write a program that generates a list of lists of the following form:

[a,b,c,...,z]⇒[[z], [y,z], [x,y,z], ... , [a,b, ... ,y,z]]

Hint: Slicing is your friend.

please write a python program

Solutions

Expert Solution

n=int(input("Enter the list size : "))
l=[]
for c in range(n):
    l.append(input())
l2=[]
for i in range(1,n+1):
    l2.append(l[-i:])
print(l2)   

The above program will take the input automatically the characters from a to z and return the result in the form of the output specified.Here as we are using the concept of slicing that if i =1 then we make it l[-1: ] which will give nals t element and l[-2:] which gives last two elements and so on upto the length.The above program is designed based on the question.chr(c) will convert the integer to the character as per the ASCII values.

SCREENSHOT OF THE CODE ALONG WITH THE OUTPUT SCREENSHOT:

BELOW I AM PROVIDING ANOTHER CODE WHERE YOU CAN TAKE THE INPUT AS THE SUER DEFINED WHICH WE CAN TAKE THE STRING INPUT.

CODE:

n=int(input("Enter the list size : "))
l=[]
for c in range(n):
    l.append(input())
l2=[]
for i in range(1,n+1):
    l2.append(l[-i:])
print(l2)   

The above program will ask the suer to enter the size of the list and then it aks the program to enter the values (For example we take 26 as the input and we enter 26 values and then we get the input and then we get the output in the desired format.

SCREENSHOT OF THE CODE AND OUTPUT :


Related Solutions

*LISP PROGRAM* 2. Write a function that, given a list of lists, returns the total length...
*LISP PROGRAM* 2. Write a function that, given a list of lists, returns the total length of all the lists. This problem can be solved two different ways. 3. Write a program that prompts the user to enter two numbers and then outputs the sum of the two numbers. 4.Write ALLODDP, a recursive function that returns T if all the numbers in a list are odd.
Grocery List Program Write a program that keeps track of the user's grocery list items. Prompt...
Grocery List Program Write a program that keeps track of the user's grocery list items. Prompt the user if they'd like to (each action is a function): See the list Display all items (if any) in the list Add item to their list Confirm with the user before adding item (y/n or yes/no) If they enter a duplicate item, notify them the item already exists Remove items from their list Confirm with the user before removing item (y/n or yes/no)...
C++ DO not use arrays to write this program. Write a program that repeatedly generates three...
C++ DO not use arrays to write this program. Write a program that repeatedly generates three random integers in the range [1, 100] and continues as follows: If the right-most digit of all the three integers is equal, the program displays them in ascending order on the screen and continues. If the generated integers have different right-most digits, they are not displayed and the program continues. The program terminates once the right-most digits of all the three random numbers are...
#Write a program in Python that given a list of positive integers, return another list where...
#Write a program in Python that given a list of positive integers, return another list where each element corresponds to the sum of the digits of the elements o#f the given list. #Example: # input # alist=[124, 5, 914, 21, 3421] # output # sum=[7, 5, 14, 3, 18]
Write a for-loop in MATLAB that generates a list of numbers such that each number is...
Write a for-loop in MATLAB that generates a list of numbers such that each number is the sum of the previous three. Initialize your list of numbers at the values of 0, 0 and 1. In other words, "0" is the first element of the list, "0" is the second element of the list, and "1" is the third element of the list. What is the 20th value in the list?
*Write in C* Write a program that generates a random Powerball lottery ticket number . A...
*Write in C* Write a program that generates a random Powerball lottery ticket number . A powerball ticket number consists of 5 integer numbers ( between 1-69) and One power play number( between 1-25).
this has to be coded in c ++ • Write a program which generates a DIFFERENT...
this has to be coded in c ++ • Write a program which generates a DIFFERENT random number between 1 and 100 everytime you run the program. Please go online and see how poeple are trying to solve this. You can submit their code. Make sure you include a comment which shows from where the code was taken. You do not need to understand the code but if you can, thats great. This program will be used in the upcoming...
Python Question Using lists, write the function non_unique(list) that takes a list list as argument. It...
Python Question Using lists, write the function non_unique(list) that takes a list list as argument. It returns a list which duplicated elements remains and each duplicated element is followed by a number which shows how many times it appears. All elements in return list should be in the same order as their appearance in the original list. For example, given the input [‘a’, ‘b’, ‘c’, ‘a’, ‘b’, ‘d’, ‘a’,‘e’], the function would return [‘a’, 3, ‘b’, 2]. Another example, ['abc',...
Given the following list of items: a. Classify the items as A, B, or C b....
Given the following list of items: a. Classify the items as A, B, or C b. Determine the economic order quantity for each item (round to the nearest whole unit) Item Estimated Annual Demand Ordering Cost Holding Cost (%) Unit Price H4-010 20,000 55 25 4.5 H5-201 60,200 65 25 6 P6-400 9,800 85 35 30.5 P6-401 14,500 55 35 14 P7-100 6,250 55 35 11 P9-103 7,500 55 45 24 TS-300 21,000 45 30 47 TS-400 45,000 45 30...
PHTHON 3 Write code that generates a list of the names of all the senders of...
PHTHON 3 Write code that generates a list of the names of all the senders of the messages in fb_data. Store it in a variable called senders. fb_data = { "data": [ { "id": "2253324325325123432madeup", "from": { "id": "23243152523425madeup", "name": "Jane Smith" }, "to": { "data": [ { "name": "Your Facebook Group", "id": "432542543635453245madeup" } ] }, "message": "Understand. Extract. Repeat.", "type": "status", "created_time": "2014-10-03T02:07:19+0000", "updated_time": "2014-10-03T02:07:19+0000" }, { "id": "2359739457974250975madeup", "from": { "id": "4363684063madeup", "name": "John Smythe" }, "to":...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT