Question: Given a list of integers from 1~9, write code to create a series of new lists, such that each new list will include one digit

Given a list of integers from 1~9, write code to create a series of new lists, such that each new list will include one digit from the original list, repeated for a number of times as indicated by the number itself. For example, assuming a list as following: [9, 6, 4, 7, 8, 2, 5], the output lists will look as the following:

Part a) Expected output:

999999999 666666 4444 7777777 88888888 22 55555

Noted that your program should be applicable when the data inside ls changes (but are still in valid range and format).

ls = [9, 6, 4, 7, 8, 2, 5]

# Start your code below # Part a

Part b) Expected output:

[9, 9, 9, 9, 9, 9, 9, 9, 9] [6, 6, 6, 6, 6, 6] [4, 4, 4, 4] [7, 7, 7, 7, 7, 7, 7] [8, 8, 8, 8, 8, 8, 8, 8] [2, 2] [5, 5, 5, 5, 5]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!