Question

Give a code fragment that sorts an array that is known to consist of items having just two distinct keys.

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

Code:-

RepeatedArr = 12,2,2,1,1,1,1,1,1,1,1,2,2,1,2,1,2,1,1,2,1,1,1,1,1] #array with two distinct elements SizeofArray = len(Repeate

Output:-

12

code

# Python3 program to print
# sorted distinct elements.

RepeatedArr = [2,2,2,1,1,1,1,1,1,1,1,2,2,1,2,1,2,1,1,2,1,1,1,1,1] #array with two distinct elements
SizeOfArray = len(RepeatedArr) #calculating the size
setOfArray = set() #adding to set
for i in range(SizeOfArray): #for loop
if RepeatedArr[i] not in setOfArray: #adding to set
setOfArray.add(RepeatedArr[i])
for i in setOfArray: #printing the array
print(i,end=" ")

Add a comment
Know the answer?
Add Answer to:
Give a code fragment that sorts an array that is known to consist of items having...
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
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