turning 'dict' output result into one string in python

Question:

I’m using Farasa library and I’m using its lemmatization module that I want to add to my nlp text cleaning code
I’ve used this code

import json
import requests

url = 'https://farasa.qcri.org/webapi/lemmatization/'
text = 'ينظم معهد الشارقة للفنون معرضاً فنياً تحت عنوان باقة الفن، وذلك عند الساعة السابعة من مساء اليوم في مقر المعهد في منطقة الفنون في حي الشويهين في الشارقة، وتتلاقى في المعرض إبداعات 62 طالباً من المنتسبين للدراسة في المعهد في كافة التخصصات الفنية .' 
api_key = "####"
payload = {'text': text, 'api_key': api_key}
data = requests.post(url, data=payload)
result = json.loads(data.text)

print(result) 

and I got this result :

{'text': ['نظم', 'معهد', 'شارقة', 'فن', 'معرض', 'فني', 'تحت', 'عنوان', 'باقة', 'فن', '،', 'ذلك', 'عند', 'ساعة', 'سابع', 'من', 'مساء', 'يوم', 'في', 'مقر', 'معهد', 'في', 'منطقة', 'فن', 'في', 'حي', 'شويه', 'في', 'شارقة', '،', 'تلاقى', 'في', 'معرض', 'إبداع', '62', 'طالب', 'من', 'منتسب', 'دراسة', 'في', 'معهد', 'في', 'كافة', 'تخصص', 'فني', '.']}

I don’t know the output type so I added print(type(result)) and I got <class 'dict'>
I tried using str() to convert it or .join() but I couldn’t get any results

I want to end up with a clean string without those commas and {text} like this

نظم معهد شارقة فن معرض فني تحت عنوان باقة فن ، ذلك عند ساعة سابع من مساء يوم في مقر معهد في منطقة فن في حي شويه في شارقة ، تلاقى في معرض إبداع 62 طالب من منتسب دراسة في معهد في كافة تخصص فني

and I don’t know how.

Asked By: Ramy Abidi

||

Answers:

You could get text list by result['text'], then join it.

print(' '.join(result['text']))
Answered By: todoit
Categories: questions Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.