1

How do I combine 2 letters such as क and ख ⟶ क्ख?

What I tried:

  • '्'.join(['क','ख']) -> 'क्‪ख'

  • print("क"+"\b"+"ख") -> 'ख' or 'क\x08ख'

  • print('क'+'्'+'ख') -> क्‪ख

  • print('क्‪ख'.replace('्',"")) -> कख

I got the answer (soln 1 worked, just had to add # -*- coding: utf-8 -*- to the top of the file)

guest
  • 19
  • 5
  • 1
    It works fine for me. Maybe your terminal is having issues rendering the unicodes? – drum Apr 28 '21 at 21:45
  • 1
    Looks like it's about ligatures, and that's not just a naive concatenation. Please take a look at this post https://stackoverflow.com/questions/9175073/convert-hexadecimal-character-ligature-to-utf-8-character – madbird Apr 28 '21 at 21:47
  • for me, it works okay in terminal and Jupiter notebook. tried to find unicode in python 3, and found that it's wrapped with [str] (https://docs.python.org/3/howto/unicode.html) now. would you mind trying like `print(str('क'+'्'+'ख'))` i got "क्ख" for this. – simpleApp Apr 28 '21 at 21:58
  • I got the same answer (`print(str('क'+'्'+'ख'))`->`क्‪ख`), but i realised when i paste क्‪ख into stackoverflow it gets converted to क्ख, but in other terminals it shows differently. (i added character "‪" to show it properly) – guest Apr 28 '21 at 22:06
  • and if you try `print(str('क' +'ख'))`, then you get two letters separately like ` कख` . is all okay now? – simpleApp Apr 28 '21 at 22:10
  • (i think my comment might be unclear) i meant क्ख instead of कख (they look similar but aren't the same like how "fi" isn't "fi") – guest Apr 28 '21 at 22:15
  • It looks like a terminal issue: if your terminal's font has ligatures, it displays the three characters as one ligature. If it doesn't, it displays them separately – Pranav Hosangadi Apr 28 '21 at 22:20
  • Could be (as [at] drum mentioned, forgot to reply), but it shows it as the same on other areas too (coCalc, replit, glitch, localhost) (also when i paste क‪‪'्ख (without the ') in stackoverflow, it shows a क्ख so it could be though) – guest Apr 28 '21 at 22:26
  • I got the answer (soln 1 worked, just had to add `# -*- coding: utf-8 -*-` to the top of the file) – guest Apr 28 '21 at 22:35
  • Please don't put the answer in the question. Instead, [answer your own question](/help/self-answer). – wjandrea Apr 29 '21 at 00:23

2 Answers2

0

(yes, i am the author of the question)

At the top of your python file, add this: # -*- coding: utf-8 -*-

And then soln. 1 works: print('्'.join(['क','ख'])) OR this one:

print('न्म'[2].join(['क','ख']))

guest
  • 19
  • 5
-1

Have each value as a string:

a, b = 'क', 'ख'

Then, to join 2 strings, you can use +

print(a + b)

Just an FYI, you might see some errors since these characters are not in the English alphabet, and in a coding project you might get some errors. Just a heads up.

Full code is as follows:

a, b = 'क', 'ख'

print(a + b)
Dugbug
  • 454
  • 2
  • 11
  • 1
    This doesn't answer his question since those characters are not right next to eachother, they are literally combined into one character. – Libra Apr 28 '21 at 21:45
  • They said that they wanted their output to be 'क्ख', which is exactly what is happening here. – Dugbug Apr 28 '21 at 21:47
  • No (कख means [ka][kha], but क्ख means [ka-kha] or [k-kh]) so that was what i meant) – guest Apr 28 '21 at 21:51
  • Americans are not used to worrying about ligatures. In many languages, two letters can "combine" to mean something different than when they are adjacent. English can have 'a' and 'e' combine to 'æ', but that doesn't change the meaning. In many languages, it does. – Tim Roberts Apr 28 '21 at 22:38