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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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):
(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
Transcribed Image 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
Expert Solution
steps

Step by step

Solved in 2 steps with 8 images

Blurred answer
Knowledge Booster
Fibonacci algorithm
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education