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)...
PYTHON    Generates a list of datetimes given a list of dates and a list of...
PYTHON    Generates a list of datetimes given a list of dates and a list of times. All possible combinations of date and time are contained within the result. The result is sorted in chronological order. For example, Input: >>> timetable([date(2019,9,27), date(2019,9,30)], [time(14,10), time(10,30)]) Output: [datetime(2019,9,27,10,30), datetime(2019,9,27,14,10), datetime(2019,9,30,10,30), datetime(2019,9,30,14,10)] Current code: from datetime import date, time, datetime def timetable(dates, times): lis = []    for c in times: for y in dates: x = f"(datetime{y},{c})" lis.append(x) #doesn't work at all
3. Write a Java program that generates a set of random strings from a given string...
3. Write a Java program that generates a set of random strings from a given string of same length where no character is ever repeated and characters belong to the original string. Examples Input: “Hello World” Output: “World oHlel”
Problem 01: GroceryCalculator Write a program to calculate the cost of a list of grocery items....
Problem 01: GroceryCalculator Write a program to calculate the cost of a list of grocery items. It includes one attribute: totalCost. It includes five user-defined methods: getItemName which asks the user to type an item name and returns the name of the item. It returns a string. getItemPrice which asks the user to type the price for an item and returns the price, which return a double. getItemQuantity which asks the user to type how many of the item they...
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?
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...
*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).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT