0

I have a list of tuples which contains Unicode text. I'm trying to display/convert it in Devanagari.

g=[]
g=[(u'\u0915\u0947\u0932\u094d\u092f\u094b ', u'\u0938\u0917\u0933\u094d\u092f\u093e\u0902\u0924 \u091a\u0921 \u096a\u096b \u0927\u093e\u0902\u0935\u0921\u094d\u092f\u094b '), (u'\u0936\u093f\u0916\u0930 \u0927\u0935\u0928\u093e\u0928 ', u'\u0938\u0917\u0933\u094d\u092f\u093e\u0902\u0924 \u091a\u0921 \u096a\u096b \u0927\u093e\u0902\u0935\u0921\u094d\u092f\u094b ')]
[(u'\u0938\u0928\u0930\u093e\u092f\u091d\u0930\u094d\u0938 \u0939\u0948\u0926\u0930\u093e\u092c\u093e\u0926 \u092e\u0941\u0902\u092c\u092f \u0907\u0902\u0921\u093f\u092f\u0928\u094d\u0938\u093e\u0915 ', u'\u092a\u0902\u0917\u0921\u093e\u0928 \u090f\u0915\u0947 \u0935\u093f\u0915\u0947\u091f\u0940\u0902\u0928\u0940 '), (u'\u092a\u0902\u0917\u0921\u093e\u0928 \u090f\u0915\u0947 \u0935\u093f\u0915\u0947\u091f\u0940\u0902\u0928\u0940 ', u'\u0939\u093e\u0930\u092f\u0932\u094b ')]
[(u'\u0939\u0948\u0926\u0930\u093e\u092c\u093e\u0926\u093e \u092c\u093f\u0932\u0940 \u0938\u094d\u091f\u0947\u0928\u0932\u0947\u0915 \u0938\u0902\u0926\u0940\u092a \u0936\u0930\u094d\u092e\u093e \u0938\u093f\u0927\u094d\u0926\u093e\u0930\u094d\u0925 \u0915\u094b\u0932 ', u'\u0939\u093e\u0923\u0947\u0902 \u092a\u094d\u0930\u0924\u094d\u092f\u0947\u0915\u0940 \u0926\u094b\u0928 \u0935\u093f\u0915\u0947\u091f\u0940 '), (u'\u0918\u0947\u0924\u0932\u094d\u092f\u094b ', u'\u0939\u093e\u0923\u0947\u0902 \u092a\u094d\u0930\u0924\u094d\u092f\u0947\u0915\u0940 \u0926\u094b\u0928 \u0935\u093f\u0915\u0947\u091f\u0940 ')]
[(u'\u0918\u0947\u0924\u0932\u0940 ', u'\u0924\u0940\u0928 \u0935\u093f\u0915\u0947\u091f '), (u'\u0918\u0947\u0924\u0932\u0940 ', u'\u090f\u0915 \u0935\u093f\u0915\u0947\u091f '), (u'\u090f\u0915 \u0935\u093f\u0915\u0947\u091f ', u'\u0936\u0930\u094d\u092e\u093e\u0928 '), (u'\u0924\u0940\u0928 \u0935\u093f\u0915\u0947\u091f ', u'\u092e\u092f\u0902\u0915\u093e\u0928 ')]
[(u'\u0938\u0928\u0930\u093e\u092f\u091d\u0930\u094d\u0938\u093e\u0928 ', u'\u0968\u0966 \u0913\u0935\u094d\u0939\u0930\u0940\u0902\u0928\u0940 \u096f \u0935\u093f\u0915\u0947\u091f\u0940 \u091c\u0948\u0924 '), (u'\u0935\u0917\u0921\u093e\u0935\u0928 \u091c\u094b\u0921\u0932\u0947\u0902 ', u'\u0968\u0966 \u0913\u0935\u094d\u0939\u0930\u0940\u0902\u0928\u0940 \u096f \u0935\u093f\u0915\u0947\u091f\u0940 \u091c\u0948\u0924 ')]
[(u'\u092a\u0930\u094d\u091c\u0933\u094d\u0933\u094b ', u'\u091c\u0948\u0924\u093e\u0902\u0924 '), (u'\u091c\u0948\u0924\u093e\u0902\u0924 ', u'\u0938\u0928\u0930\u093e\u092f\u091d\u0930\u094d\u0938\u093e\u091a\u094d\u092f\u093e \u0926\u0940\u092a\u0930 \u0939\u0941\u0921\u093e ')]
[(u'\u090f\u0915\u0947 \u0935\u093f\u0915\u0947\u091f\u0940\u0928 \u091c\u0948\u0924 ', u'\u0938\u0928\u0930\u093e\u092f\u091d\u0930\u094d\u0938\u093e\u0915 ')]
ls=[]
for x in g[0]:

    ls.append(x)
    print (x)

This is what I get. OUTPUT: एके विकेटीन जैत सनरायझर्साक

snakecharmerb
  • 36,887
  • 10
  • 71
  • 115
Sheryl
  • 51
  • 7

1 Answers1

0

Given a list of tuples of strings, you can use a generator expression to "flatten" the collection into a list of strings, and then call str.join on the list to create a single string.

>>> g =[(u'\u0915\u0947\u0932\u094d\u092f\u094b ', u'\u0938\u0917\u0933\u094d\u092f\u093e\u0902\u0924 \u091a\u0921 \u096a\u096b \u0927\u093e\u0902\u0935\u0921\u094d\u092f\u094b '), (u'\u0936\u093f\u0916\u0930 \u0927\u0935\u0928\u093e\u0928 ', u'\u0938\u0917\u0933\u094d\u092f\u093e\u0902\u0924 \u091a\u0921 \u096a\u096b \u0927\u093e\u0902\u0935\u0921\u094d\u092f\u094b ')]
>>> print ''.join(item for tuple_ in g for item in tuple_)

केल्यो सगळ्यांत चड ४५ धांवड्यो शिखर धवनान सगळ्यांत चड ४५
snakecharmerb
  • 36,887
  • 10
  • 71
  • 115
  • How do I separate out the lists?@snakecharmerb – Sheryl May 01 '19 at 07:25
  • If your data is actually a list of lists of tuples then you can use the techniques in the answer to [this question](https://stackoverflow.com/questions/10823877/what-is-the-fastest-way-to-flatten-arbitrarily-nested-lists-in-python) – snakecharmerb May 01 '19 at 07:27
  • Actually the output I get is something this way [x,y,z] [s,j,k]…….[s,j,i] All separate lists – Sheryl May 01 '19 at 07:36
  • g=(list( filter( lambda x: x[0] in component and x[1] in component, graph.edges ) )) print g – Sheryl May 01 '19 at 07:37
  • https://stackoverflow.com/questions/55771589/extracting-edge-data-from-a-networkx-graph Its a contnuation of this question. Could you please have a look at it – Sheryl May 01 '19 at 07:44