nerdexam
GIAC

GPYC · Question #46

Given that mylist = [1,3,2,1,4,5,3] how do you remove all occurrences of the number 1 from the list in Python?

The correct answer is A. mylist=[x for x in mylist if x!= 1]. You've hit your limit · resets 1pm (America/New_York)

Python Fundamentals & Command Line Tools

Question

Given that mylist = [1,3,2,1,4,5,3] how do you remove all occurrences of the number 1 from the list in Python?

Options

  • Amylist=[x for x in mylist if x!= 1]
  • Bmylist.remove(1, mylist.count(1))
  • Cmylist.replace(1, "")
  • Dmylist.remove(1)

How the community answered

(17 responses)
  • A
    82% (14)
  • B
    6% (1)
  • C
    12% (2)

Explanation

You've hit your limit · resets 1pm (America/New_York)

Topics

#list comprehension#filtering#remove elements#list manipulation

Community Discussion

No community discussion yet for this question.

Full GPYC Practice