Putting individual lists together

Asked 2 years ago, Updated 2 years ago, 46 views

lang_type=['ko','en','es','vi']

text_src = translator.translate(user_text).src
if text_src==lang_type[0]: 
    telegram.Bot(TelegramToken).send_message(user_id,translator.translate(user_text, dest=lang_type[1]).text) 
    telegram.Bot(TelegramToken).send_message(user_id,translator.translate(user_text, dest=lang_type[2]).text) 
    telegram.Bot(TelegramToken).send_message(user_id,translator.translate(user_text, dest=lang_type[3]).text) 

elif text_src==lang_type[1]:
    telegram.Bot(TelegramToken).send_message(user_id,translator.translate(user_text, dest=lang_type[0]).text)
    telegram.Bot(TelegramToken).send_message(user_id,translator.translate(user_text, dest=lang_type[2]).text)
    telegram.Bot(TelegramToken).send_message(user_id,translator.translate(user_text, dest=lang_type[3]).text)

elif text_src==lang_type[2]: 
    telegram.Bot(TelegramToken).send_message(user_id,translator.translate(user_text, dest=lang_type[0]).text)
    telegram.Bot(TelegramToken).send_message(user_id,translator.translate(user_text, dest=lang_type[1]).text)
    telegram.Bot(TelegramToken).send_message(user_id,translator.translate(user_text, dest=lang_type[3]).text)

else: 
    telegram.Bot(TelegramToken).send_message(user_id,translator.translate(user_text, dest=lang_type[0]).text)
    telegram.Bot(TelegramToken).send_message(user_id,translator.translate(user_text, dest=lang_type[1]).text)
    telegram.Bot(TelegramToken).send_message(user_id,translator.translate(user_text, dest=lang_type[2]).text)

When I print this code, I print out messages individually, so can you tell me how to print all of these individual messages out in one message?

[1:3] We simply tried it together, but it didn't work.

python list

2022-09-20 11:17

2 Answers

This is the code that implements what Yeopto explained. I didn't test it. Please refer to it.

text_src = translator.translate(user_text).src

lang_type_ = [ lang for lang in lang_type if lang != text_src ] # 1 filter

messages = [ translator.translate(user_text, dest = lang).text for lang in lang_type_ ] # 2 mapping

joined_message = ' '.join(messages) #3  join

telegram.Bot(TelegramToken).send_message(user_id, joined_message) # 4 send


2022-09-20 11:17

So if the language you typed is Korean, you're not translating it into Korean, but translating it into the rest of the languages (English, Spanish, Vietnamese) and showing it all at once, right?

If you've learned about the circulating materials, I think the following explanation will be enough.

Related references:

Try it yourself from here! Good luck.


2022-09-20 11:17

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.