exam questions

Exam PT0-002 All Questions

View all questions & answers for the PT0-002 exam

Exam PT0-002 topic 1 question 389 discussion

Actual exam question from CompTIA's PT0-002
Question #: 389
Topic #: 1
[All PT0-002 Questions]

A penetration tester is troubleshooting the right value for the urls variable that should be used in the following script:



Which of the following instructions in a Python script will prevent duplicate entries in the output and work with the script above?

  • A. [u for u in url_list if u not in url_list]
  • B. list({u: True for u in url_list}.keys())
  • C. f"{u: True for u in url_list}"
  • D. json.dumps({u: True for u in url_list}.keys())
Show Suggested Answer Hide Answer
Suggested Answer: B 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
NappyGamer
Highly Voted 7 months, 3 weeks ago
Selected Answer: B
To prevent duplicate entries in the url_list, the best choice from the options provided is: B. list({u: True for u in url_list}.keys()) This option uses a dictionary comprehension to create a dictionary where each URL is a key (removing duplicates, as dictionary keys must be unique), and then retrieves the keys as a list. Here's how you can incorporate it into your script: url_list = ['https://localhost', 'http://127/0/0/1'] + list1 + list2 urls = list({u: True for u in url_list}.keys()) for url in urls: print(requests.get(url).text) The other options either don't achieve the desired result or are syntactically incorrect.
upvoted 5 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago