-2

Why is this weird behaviour:

a  = ['This','is','some','banana']
"_".join(sorted(a)).

Output -

This_is_banana_some

It should give the output -

is_banana_some_this

Am I missing something?

Adriaan
  • 17,741
  • 7
  • 42
  • 75
Akash Singh
  • 171
  • 1
  • 10
  • 1
    Why would `T` be between `i` and `t`? `T` is 84 and `i` is 105, so `This` should be before `is` – Dharman Jan 07 '20 at 14:31

1 Answers1

0

You need to specify the sorting key - lowercase str in your case.

"_".join(sorted(a, key=str.lower))

This works. By default python places uppercase first.

Adarsh Chavakula
  • 1,509
  • 19
  • 28