-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,081
  • 7
  • 36
  • 71
Akash Singh
  • 151
  • 1
  • 9
  • 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,499
  • 18
  • 26