Please is there any other way to write the line l = [x for x in l if x not in n] and write the code another way ? Please help me on python without using "break" or "continue", and no global variables...


Please is there any other way to write the line l = [x for x in l if x not in n] and write the code another way ? Please help me on python without using "break" or "continue", and no global variables in functions.



def remove_pairs(1):<br>(list of str)->list of str<br>Returns a copy of list 1 where all the pairs from 1 are removed AND<br>the elements of the new list shuffled<br>Precondition: elements of 1 are cards represented as strings described above<br>Testing:<br>Note that for the individual calls below, the function should<br>return the displayed list but not necessarily in the order given in the examples.<br>>>> remove_pairs(['94', '54',<br>['104', '24', '3♡',<br>>>> remove_pairs(['104'<br>['24', '50',<br>'44'<br>'54', '7♡', 'A^', '104', 'Q♡', '8♡'.<br>190', '100<br>'J♡', '10♡',<br>'J h', '3♡'])<br>'KO', 'A',<br>'A',<br>6',<br>'KO',<br>'J4', 'Q0']<br>'AO',<br>'24', 'Q*', 'KA', 'Qo', 'Jª', 'A♡',<br>'44',<br>'7♡',<br>'80',<br>194',<br>'24', '50',<br>'AO'j<br>'100'])<br>'6', '94'<br>no_pairs=[]<br>for i in ('2','3','4','5','6','7','8','9','10','J','Q','K','A'):<br>n = []<br>for j in range (len(1)):<br>if 1[j].find (i) != -1:<br>n.append (1[j])<br>if len(n) == 2 or len(n) == 3:<br>1.remove (n[0])<br>1.remove (n[1])<br>elif len(n) == 4:<br>1 = [x for x in 1 if x not in n]<br>no_pairs = 1<br>random. shuffle(no_pairs)<br>return no_pairs<br>

Extracted text: def remove_pairs(1): (list of str)->list of str Returns a copy of list 1 where all the pairs from 1 are removed AND the elements of the new list shuffled Precondition: elements of 1 are cards represented as strings described above Testing: Note that for the individual calls below, the function should return the displayed list but not necessarily in the order given in the examples. >>> remove_pairs(['94', '54', ['104', '24', '3♡', >>> remove_pairs(['104' ['24', '50', '44' '54', '7♡', 'A^', '104', 'Q♡', '8♡'. 190', '100 'J♡', '10♡', 'J h', '3♡']) 'KO', 'A', 'A', 6', 'KO', 'J4', 'Q0'] 'AO', '24', 'Q*', 'KA', 'Qo', 'Jª', 'A♡', '44', '7♡', '80', 194', '24', '50', 'AO'j '100']) '6', '94' no_pairs=[] for i in ('2','3','4','5','6','7','8','9','10','J','Q','K','A'): n = [] for j in range (len(1)): if 1[j].find (i) != -1: n.append (1[j]) if len(n) == 2 or len(n) == 3: 1.remove (n[0]) 1.remove (n[1]) elif len(n) == 4: 1 = [x for x in 1 if x not in n] no_pairs = 1 random. shuffle(no_pairs) return no_pairs

Jun 07, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here