0

I need to map each Unicode value in final2 with the Unicode values present as keys in the dictionary to print the Devanagari characters in a string. Right now the output generated is an empty list. How do I print the Devanagari characters in a string? devadict is a dictionary containing Unicode values and Devanagari characters.

devadict= {
'u0900':' ऀ',
'u0901':' ँ',
'u0902':' ं',
'u0903': 'ः',
'u0904': 'ऄ',
'u0905': 'अ',
'u0906': 'आ',
'u0907': 'इ',
'u0908': 'ई',
'u0909': 'उ',
'u090A': 'ऊ',
'u090B': 'ऋ',
'u090C': 'ऌ',
'u090D': 'ऍ',
'u090E': 'ऎ',
'u090F': 'ए',
'u0910': 'ऐ',
'u0911': 'ऑ',
'u0912': 'ऒ',
'u0913': 'ओ',
'u0914': 'औ',
'u0915': 'क',
'u0916': 'ख',
'u0917': 'ग',
'u0918': 'घ',
'u0919': 'ङ',
'u091A': 'च',
'u091B': 'छ',
'u091C': 'ज',
'u091D': 'झ',
'u091E': 'ञ',
'u091F': 'ट',
'u0920': 'ठ',
'u0921': 'ड',
'u0922': 'ढ',
'u0923': 'ण',
'u0924': 'त',
'u0925': 'थ',
'u0926': 'द',
'u0927': 'ध',
'u0928': 'न',
'u0929': 'ऩ',
'u092A': 'प',
'u092B': 'फ',
'u092C': 'ब',
'u092D': 'भ',
'u092E': 'म',
'u092F': 'य',
'u0930': 'र',
'u0931': 'ऱ',
'u0932': 'ल',
'u0933': 'ळ',
'u0934': 'ऴ',
'u0935': 'व',
'u0936': 'श',
'u0937': 'ष',
'u0938': 'स',
'u0939': 'ह',
'u093A': 'ऺ',
'u093B': 'ऻ',
'u093C':' ़' ,
'u093D': 'ऽ',
'u093E': 'ा',
'u093F': 'ि',
'u0940': 'ी',
'u0941':' ु',
'u0942':' ू',
'u0943':' ृ',
'u0944':' ॄ',
'u0945':' ॅ',
'u0946':' ॆ',
'u0947':' े',
'u0948':' ै',
'u0949': 'ॉ',
'u094A': 'ॊ',
'u094B': 'ो',
'u094C': 'ौ',
'u094D':' ्',
'u094E': 'ॎ',
'u094F': 'ॏ',
'u0950': 'ॐ',
'u0951':'',
'u0952': '-',
'u0953':' ॓',
'u0954':' ॔',
'u0955':' ॕ',
'u0956': 'ॖ',
'u0957': 'ॗ',
'u0958': 'क़',
'u0959': 'ख़ ',
'u095A': 'ग़ ',
'u095B': 'ज़' ,
'u095C': 'ड़' ,
'u095D': 'ढ़' ,
'u095E': 'फ़' ,
'u095F': 'य़',
'u0960': 'ॠ',
'u0961': 'ॡ' ,
'u0962':' ॢ' ,
'u0963':' ॣ',
'u0964': '।' ,
'u0965': '॥' ,
'u0966': '०' ,
'u0967': '१' ,
'u0968': '२' ,
'u0969': '३' ,
'u096A': '४' ,
'u096B': '५' ,
'u096C': '६' ,
'u096D': '७' ,
'u096E': '८' ,
'u096F': '९',
'u0970': '॰',
'u0971': 'ॱ ',
'u0972': 'ॲ' ,
'u0973': 'ॳ' ,
'u0974': 'ॴ' ,
'u0975': 'ॵ' ,
'u0976': 'ॶ' ,
'u0977': 'ॷ' ,
'u0978': 'ॸ' ,
'u0979': 'ॹ' ,
'u097A': 'ॺ' ,
'u097B': 'ॻ' ,
'u097C': 'ॼ' ,
'u097D': 'ॽ' ,
'u097E': 'ॾ' ,
'u097F': 'ॿ',
}
final2=[(u'\u0938\u0928\u0930\u093e\u092f\u091d\u0930\u094d\u0938  \u093e\u0915 \u090f\u0915\u0947 \u0935\u093f\u0915\u0947\u091f\u0940\u0928 \u091c\u0948\u0924', u'\n\u0907\u0902\u0921\u093f\u092f\u0928 \u092a\u094d\u0930\u093f\u092e\u0940\u092f\u0930 \u0932\u093f\u0917\u0947\u0902\u0924 \u0915\u093e\u0932 \u091c\u093e\u0932\u094d\u0932\u0947 \u0909\u092e\u0933\u0936\u0940\u0915 \u0935\u093e\u0921\u094b\u0935\u092a\u0940 \u092e\u0945\u091a\u0940\u0902\u0924 \u092f\u0947\u091c\u092e\u093e\u0928 \u0938\u0928\u0930\u093e\u092f\u091d\u0930\u094d\u0938 \u0939\u0948\u0926\u0930\u093e\u092c\u093e\u0926 \u092a\u0902\u0917\u0921\u093e\u0928 \u0938\u0927\u094d\u092f\u093e\u091a\u094b \u0935\u0938\u094d\u0924\u093e\u0926 \u092e\u0941\u0902\u092c\u092f \u0907\u0902\u0921\u093f\u092f\u0928\u094d\u0938\u093e\u0915 \u090f\u0915\u0947 \u0935\u093f\u0915\u0947\u091f\u0940\u0902\u0928\u0940 \u0939\u093e\u0930\u092f\u0932\u094b', u'\n\u0967\u096a\u096e \u0927\u093e\u0902\u0935\u0921\u094d\u092f\u093e\u0902\u091a\u094b \u092b\u093e\u091f\u0932\u093e\u0935 \u0915\u0930\u092a\u0940 \u0938\u0928\u0930\u093e\u092f\u091d\u0930\u094d\u0938\u093e\u0928 \u0928\u093f\u0927\u093e\u0930\u0940\u0924 \u0968\u0966 \u0913\u0935\u094d\u0939\u0930\u0940\u0902\u0928\u0940 \u096f \u0935\u093f\u0915\u0947\u091f\u0940 \u0935\u0917\u0921\u093e\u0935\u0928 \u091c\u0948\u0924 \u091c\u094b\u0921\u0932\u0947\u0902', u'\n\u0913\u092a\u0928\u0930 \u0936\u093f\u0916\u0930 \u0927\u0935\u0928\u093e\u0928 \u0938\u0917\u0933\u094d\u092f\u093e\u0902\u0924 \u091a\u0921 \u096a\u096b \u0927\u093e\u0902\u0935\u0921\u094d\u092f\u094b \u0915\u0947\u0932\u094d\u092f\u094b \u0906\u0938\u0932\u094d\u092f\u094b \u0924\u0930\u0940 \u0938\u0928\u0930\u093e\u092f\u091d\u0930\u094d\u0938\u093e\u091a\u094d\u092f\u093e \u091c\u0948\u0924\u093e\u0902\u0924 \u0926\u0940\u092a\u0930 \u0939\u0941\u0921\u093e \u092a\u0930\u094d\u091c\u0933\u094d\u0933\u094b', u'\u0924\u093e\u0923\u0947\u0902 \u0928\u093e\u092c\u093e\u0926 \u0969\u0968 \u0927\u093e\u0902\u0935\u0921\u094d\u092f\u093e\u0902\u091a\u0940 \u0916\u0947\u0933\u0940 \u0915\u0930\u0924\u0928\u093e \u092a\u0902\u0917\u0921\u093e\u0915 \u091c\u0948\u0924 \u092e\u0947\u0933\u094b\u0935\u0928 \u0926\u093f\u0932\u0947\u0902', u'\u0907\u0935\u094d\u0939\u0940\u0928 \u0932\u0947\u0935\u093f\u0938\u093e\u0928 \u0968\u096f, \u0915\u093f\u0930\u094b\u0928 \u092a\u094b\u0932\u093e\u0930\u094d\u0921 \u0906\u0928\u0940 \u0938\u0942\u0930\u094d\u092f\u0915\u0941\u092e\u093e\u0930 \u092f\u093e\u0926\u0935 \u0939\u093e\u0923\u0947\u0902 \u092a\u094d\u0930\u0924\u094d\u092f\u0947\u0915\u0940 \u0968\u096e \u0927\u093e\u0902\u0935\u0921\u094d\u092f\u094b \u0915\u0947\u0932\u094d\u092f\u094b', u'\u0968\u0969 \u092c\u0949\u0932\u093e\u0902\u0928\u0940 \u0968\u096e \u0927\u093e\u0902\u0935\u0921\u094d\u092f\u094b \u0915\u0930\u0942\u0928 \u0924\u094b \u0938\u094d\u091f\u0947\u0928\u0932\u0947\u0915\u093e\u091a\u094b \u0936\u093f\u0915\u093e\u0930 \u0925\u093e\u0930\u0932\u094b', u'\n\u092c\u0947\u0928 \u0915\u091f\u093f\u0902\u0917 \u0930\u093e\u0936\u093f\u0926 \u0916\u093e\u0928\u093e\u091a\u0940 \u0917\u0941\u0917\u0932\u0940 \u0938\u092e\u091c\u0941\u092a\u093e\u0915 \u0905\u092a\u0947\u0936\u0940 \u0925\u093e\u0930\u0932\u094b \u0906\u0928\u0940 \u096f \u0927\u093e\u0902\u0935\u0921\u094d\u092f\u094b \u0915\u0930\u0942\u0928 \u092a\u0930\u0924 \u0917\u0947\u0932\u094b', u'')]
final3=[]
for x, y in devadict.items():
    for j in final2:
    if(x==j):
        final3.append(y)

print final3
#Output: []
Sandeep
  • 155
  • 1
  • 14
Sheryl
  • 79
  • 7
  • is the list final2 properly formatted? – Sandeep Mar 04 '19 at 06:25
  • Your question is little ambiguous. Can you update your question with the desired output you're looking for?? – Pankaj Mar 04 '19 at 06:31
  • list final2 is the output of a previous step. – Sheryl Mar 04 '19 at 06:46
  • Expected output should be this सनरायझर्साक एके विकेटीन जैत,इंडियन प्रिमीयर लिगेंत काल जाल्ले उमळशीक वाडोवपी मॅचींत येजमान सनरायझर्स हैदराबाद पंगडान सध्याचो वस्ताद मुंबय इंडियन्साक एके विकेटींनी हारयलो, १४८ धांवड्यांचो फाटलाव करपी सनरायझर्सान निधारीत २० ओव्हरींनी ९ विकेटी वगडावन जैत जोडलें, ओपनर शिखर धवनान सगळ्यांत चड ४५ धांवड्यो केल्यो आसल्यो तरी सनरायझर्साच्या जैतांत दीपर हुडा पर्जळ्ळो, ताणें नाबाद ३२ धांवड्यांची खेळी करतना पंगडाक जैत मेळोवन दिलें, इव्हीन लेविसान २९, किरोन पोलार्ड आनी सूर्यकुमार यादव हाणें प्रत्येकी २८ धांवड्यो केल्यो – Sheryl Mar 04 '19 at 06:49
  • The word "सनरायझर्साक" is represented as u0938\u0928\u0930\u093e\u092f\u091d\u0930\u094d\u0938 in Unicode. So I'm trying to get the output in Devanagari form from Unicode. – Sheryl Mar 04 '19 at 06:52
  • 1
    The string in `final2` already contains perfectly good Unicode text. Simply `print` it (on a terminal where you have Unicode support enabled, which might be a challenge if you are on Windows or CP/M). Demo: https://ideone.com/6FAX2a This is a very common FAQ. – tripleee Mar 04 '19 at 07:14

1 Answers1

0

Just remove Unicode i.e "u" symbol from the list. And run the same in the Python 3. That would give you the expected results.

For python 2.7.15. Try this,

ls=[]
for i in final2[0]:
    ls.append(i)
    print (i)

Input: enter image description here

Output: enter image description here

Parul Garg
  • 102
  • 1
  • 10