Question

Write a program in ADA that should be able to read two lists and produce as...

Write a program in ADA that should be able to read two lists and produce as output the shuffle of two lists (all shuffledlists): You type [a,b,c] [1,2,3] and as output you will obtain [a,b,c,1,2,3]; [a,b,1,c,2,3]; .... [1,2,3,a,b,c] The representation of list would be your choice (arrays or linked lists)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

we can have a problem in which we need to perform shuffle operation in list. This task is easy and there are straightforward functionalities available in Python to perform this. But sometimes, we need to shuffle two lists so that their shuffle orders are consistent. Let’s discuss a way in which this task can be performed.

Method : Using zip() + shuffle() + * operator
In this method, this task is performed in three steps. Firstly, the lists are zipped together using zip(). Next step is to perform shuffle using inbuilt shuffle() and last step is to unzip the lists to separate lists using * operator.

import random

# initializing lists

test_list1 = [6, 4, 8, 9, 10]

test_list2 = [1, 2, 3, 4, 5]

# printing lists

print("The original list 1 : " + str(test_list1))

print("The original list 2 : " + str(test_list2))

# Shuffle two lists with same order

# Using zip() + * operator + shuffle()

temp = list(zip(test_list1, test_list2))

random.shuffle(temp)

res1, res2 = zip(*temp)

# Printing result

print("List 1 after shuffle : " + str(list(res1)))

print("List 2 after shuffle : " + str(list(res2)))

Output :

The original list 1 : [6, 4, 8, 9, 10] The original list 2 : [1, 2, 3, 4, 5] List 1 after shuffle : [6, 10, 4, 8, 9] List 2 after shuffle : [1, 5, 2, 3, 4]
Add a comment
Know the answer?
Add Answer to:
Write a program in ADA that should be able to read two lists and produce as...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program to subtract large unsigned integers. Your program should prompt and read in two...

    Write a program to subtract large unsigned integers. Your program should prompt and read in two large unsigned integers. The two large integers should be stored arrays, one array for each integer. The integers should be stored with one digit per location in the two arrays. The first integer should be no smaller than the second. Your program should subtract the second integer from the first. The result should be stored in an array, again one digit per location in...

  • Write a program to subtract large unsigned integers. Your program should prompt and read in two...

    Write a program to subtract large unsigned integers. Your program should prompt and read in two large unsigned integers. The two large integers should be stored arrays, one array for each integer. The integers should be stored with one digit per location in the two arrays. The first integer should be no smaller than the second. Your program should subtract the second integer from the first. The result should be stored in an array, again one digit per location in...

  • 2. Write a program to read two lists of names from two input files and then...

    2. Write a program to read two lists of names from two input files and then match the names in the two lists using Co-sequential Match based on a single loop. Output the names common to both the lists to an output file, In Java

  • PYTHON: Using Lists and Arrays! 5. In a program, write a function that accepts two arguments:...

    PYTHON: Using Lists and Arrays! 5. In a program, write a function that accepts two arguments: a list, and a number n. The program should generate 20 random numbers, in the range of 1 through 100, and assign each number to the list. The program should also ask the user to pick a number from 1 through a 100 and assign that number to n. The function should display all of the number in the list that are greater than...

  • (20 points) ) Write a Python program which merges two sorted singly linked lists and return...

    (20 points) ) Write a Python program which merges two sorted singly linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. Example: Example: Input: 1->2- >4, 1->3->4 Output: 1->1->2->3 ->4->4

  • C# code Arrays and Linked Lists: Write C++/Java/C#/Python code to declare an array of linked lists...

    C# code Arrays and Linked Lists: Write C++/Java/C#/Python code to declare an array of linked lists of any primitive type you want. (Array of size 2020) (This could be based on MSDN libraries or the lab) – you do not need to instantiate any of the linked lists to contain any actual values. Paste your code for that here (this should only be one line) Based on your code or the lab from 4 or your doubly linked list from...

  • The file lab10movies.cpp contains a program that allows the user to read movie names and movie re...

    Please answer using C++ The file lab10movies.cpp contains a program that allows the user to read movie names and movie release dates from a file called movies.txt. The data is read into a single ended linked list. Once all the data has been read in, the user is given a menu option with 3 choices. Choice 1 will list all movies released before a specified year, Choice 2 will list all movies stored in the linked list, and Choice 3...

  • programing in c language Write a program, using the following functions, that reads two polynomials and...

    programing in c language Write a program, using the following functions, that reads two polynomials and prints the polynomials before and after the addition. a) polyRead - Read in a polynomial and convert it to its linked list representation. - Return a pointer to the header node of this polynomial. b) polyWrite - Output a polynomial using a form that clearly displays it. c) polyAdd - Compute c = a + b. Do not change either a or b. where,...

  • Program is to be written In C++, The output should look like the screen shot. It...

    Program is to be written In C++, The output should look like the screen shot. It should allow the user to continue to ask the user to enter all employee ID's until done and then prompt the user to enter the hours and pay rate for each employee ID. Please help:( Can you please run the program to make sure the output is just like the screenshot please? It needs to have the output that is in the screenshot provided,...

  • Write in Java! Do NOT write two different programs for Deck and Card, it should be...

    Write in Java! Do NOT write two different programs for Deck and Card, it should be only one program not 2 separate ones!!!!!! The Learning Goal for this exercise is to use and understand and know the difference between arrays and array lists. !!!!Use at least one array defined in your code and two array lists defined by the operation of your code!!!! The array should be 52 elements and contain a representation of a standard deck of cards, in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT