Question

This is a python question, I need to remove elements that are strictly smaller than the...

This is a python question, I need to remove elements that are strictly smaller than the other elements.

For example, 
temp = [[8,7],[5,5],[9,6],[10,5],[11,4],[12,3],[13,2],[8,8]]

[8,7] will be removed as it is strictly smaller than [8,8]

[5,5] will be removed as it is strictly smaller than [10,5] and [8,8]

Neither [13,2] nor [12,3] nor [11,4] nor [10,5] nor [9,6] nor [8,8] will be removed because they are not strictly smaller than each other.

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

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

#code

temp = [[8,7],[5,5],[9,6],[10,5],[11,4],[12,3],[13,2],[8,8]]
#creating a list of elements that will be removed
toRemove=[]
#looping through each number pair in temp
for i in range(len(temp)):
    #storing the two numbers in x1 and y1
   
x1,y1=temp[i]
    #looping through each and every other number pairs
   
for j in range(len(temp)):
        #making sure that this element is not comparing to itself
       
if i!=j:
            #storing current number pair in x2, y2
           
x2,y2=temp[j]
            #checking if x1,y1 is strictly smaller than x2,y2
           
if x1<=x2 and y1<=y2:
                #adding pair [x1,y1] to the toRemove list
               
toRemove.append(temp[i])
              break #end of inner loop

#now we just loop through each element in toRemove

for i in toRemove:
    #and remove each value from temp
   
temp.remove(i)

#now temp will contain the values [[9, 6], [10, 5], [11, 4], [12, 3], [13, 2], [8, 8]]
print(temp)

#output

[[9, 6], [10, 5], [11, 4], [12, 3], [13, 2], [8, 8]]

Add a comment
Know the answer?
Add Answer to:
This is a python question, I need to remove elements that are strictly smaller than the...
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
  • I need some help on this assembly question, it has to be done strictly in Intel...

    I need some help on this assembly question, it has to be done strictly in Intel x86 64 bit assembly language and the other part in C language The faction findRange find the range of the numbers in a given amay and retums the range The range is defined as the difference between the maximum number and the minimum number in the given amay write the function findRange both in C and in Assembly. The function stub for findRange is...

  • Hey guys I need help with this question with 3 sub-problems. f test remove short synonyms () Define the remove shorti s...

    Hey guys I need help with this question with 3 sub-problems. f test remove short synonyms () Define the remove shorti synonyms function which is passed a dictionary as a parameter- The keys of the parameter dictionary are words and the corresponding values are 1ists of synonyms (synonyms are words which have the same or nearly the same meaning). The function romoves all the eynonyme which have ous than 8 charactors from each corresponding list of synonyms-As well, the funet...

  • Need help on question No.5 In python Must use recursion Must use recursion Must use recursion...

    Need help on question No.5 In python Must use recursion Must use recursion Must use recursion Thank you LinkedList MISU (Annoyed that this means you don't have much flexibility about how to implement this function? I apologizel But I don't regret it - I think that these debug printouts will help most students.) 5 accordion(old head) This function takes an old list, removes every other node, and then returns the updated list. Old nodes, which are removed from the list,...

  • This question is on PYTHON Object Oriented Programming using Lists only. I need the full python...

    This question is on PYTHON Object Oriented Programming using Lists only. I need the full python coding for this question. Write a FlightBooking class with 2 collections: flight(list) and landing(list). Follow names in the UML diagram given below. UML DIAGRAM: FlightBooking _flight: list _landing: list __init__(self) addFlight(self,flight) addLanding(self,landing) removeFlight(self,pilot,flightNo) removeLanding(self,landingDateTime,destination) searchFlight(self,pilot,flightNo) : Flight searchLanding(self,landingDateTime,destination) : Landing flightStr(self) : string landingStr(self) : string 1. Constructor has 0 parameters, set collections to empty lists. 2. Add methods for both collections: - 1...

  • Python Expert, I need your help: I need to write a function(rev_int_rec) that take an integet...

    Python Expert, I need your help: I need to write a function(rev_int_rec) that take an integet number(num = 1234567) and retrive the last digit using (lastDigit = num % 10) and add it to a queue. Remove each last digit from num using the % operator Add each last digit to the queue, with each round of recursion reduce num by dividing by 10. Base case is when num is less than 10 # Base case: If num < 10...

  • 10q I need help this is a python language For the following question, refer to the...

    10q I need help this is a python language For the following question, refer to the Python module on the right, as well as the name of the file that contains each module. 1) What is the output of the following code?. import animals alist = [animals.cat('Garfield'), animals.Dog('odie'), animals. Fox ('Nicholas P. wilde'), animals. Animal ('Judy Hopps')] File animals.py class Animal: def _init__(self, name): self.name = name def getName(self): return self.name for a in alist: print( a.getName() + ', '...

  • I need to write a paint job estimator program in python. I have most of it...

    I need to write a paint job estimator program in python. I have most of it down but i keep getting errors and I dont know how to fix it or what im doing worng specs: A painting company has determined that for every 350 square feet of wall space, one gallon of paint and six hours of labor are required. The company charges $62.25 per hour for labor. Write a program call paintjobestimator.py that asks the user to enter...

  • i need python code, thank you very much! characters) and prints ) 3. Write function, smallestCharacterLargerThan(keyChar,...

    i need python code, thank you very much! characters) and prints ) 3. Write function, smallestCharacterLargerThan(keyChar, inputString) that takes as input key character, keyChar, and a string of one or more letters (and no other the "smallest" character in the string that is larger than keyChar, where one character is smaller than another if it occurs earlier in the alphabet (thus 'C is smaller than 'y' and both are larger than 'B') and 2) the index of the final occurrence...

  • Attention!!!!!!! I need python method!!!!!!!!! the part which need to edit is below: i nee...

    attention!!!!!!! I need python method!!!!!!!!! the part which need to edit is below: i need python one!!!!!!!!! the part below is interface for the range search tree which don’t need to modify it. Week 3: Working with a BST TODO: Implement a Binary Search Tree (Class Name: RangesizeTree) Choose one language fromJava or Python. Iin both languages,there is an empty main function in the Range Size Tree file. The main function is not tested, however, it is provided for you...

  • Hi, I need some help with the following question. I need the answer in Python please....

    Hi, I need some help with the following question. I need the answer in Python please. 10.23 LAB: Warm up: People's weights (Lists) (1) Prompt the user to enter four numbers, each corresponding to a person's weight in pounds. Store all weights in a list. Output the list. (2 pts) Ex: Enter weight 1: 236.0 Enter weight 2: 89.5 Enter weight 3: 176.0 Enter weight 4: 166.3 Weights: [236.0, 89.5, 176.0, 166.3] (2) Output the average of the list's elements...

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