Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Creating two lists out of tuple with occasional double value for one list

I am currently working with tuples in Python an came upon this problem:

I have a tuple that looks like this:

[("mother", ["Mutter"]), ("and", ["und"]), ("father", ["Vater"]), ("I", ["ich", "mich"]),("not", ["nicht"]), ("at", ["dort", "da"]), ("home", ["Haus", "Zuhause"]), ("now", ["jetzt"])]

i need to create two lists, one, where the englisch words are stored and one, where the German words are stored, but I don’t now how, since sometimes there are two German words for one English word.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Is there a nicer way than manually counting through the tuple and storing the words like that?

Thank you for your help!

>Solution :

Heres a quick and easy way to do it:

wordlist = [("mother", ["Mutter"]), ("and", ["und"]), ("father", ["Vater"]), ("I", ["ich", "mich"]),("not", ["nicht"]), ("at", ["dort", "da"]), ("home", ["Haus", "Zuhause"]), ("now", ["jetzt"])]

english = []
german = []

for pair in wordlist:
  english.append(pair[0])
  for item in pair[1]: german.append(item)

print(english)
print(german)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading