Python · Question 10 · Medium

What will be the output of the following Python code?

print("-".join(sorted("delhi")))
  1. d-e-l-h-i
  2. l-i-h-e-d
  3. dehil
  4. d-e-h-i-l
Answer and explanation

Answer: D. d-e-h-i-l

Explanation: sorted("delhi") returns the characters in alphabetical order as a list ['d', 'e', 'h', 'i', 'l'], and "-".join puts a hyphen between them.

Previous: What will be the output of the following Python code? · Next: What will be the output of the following Python code?

Practise python

Try a fresh set of python questions with an explanation after every answer, free and without signing up: Python practice. Or sit a full placement mock test.

More python questions

More technical & programming practice

Data Structures · Algorithms · Object-Oriented Programming · DBMS · SQL · Operating Systems · Computer Networks · Software Engineering

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge