Python Forum

Full Version: Lists in list for newbies
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone,

First of all merry Christmas to all of you :D

Now, my issue is that : I'm trying to script something that allow me to scrape data from a bi-lingual web page to translate and store translations in a unique list (for after that put all that in a .xlsx page but not for now lol :p).

For example, from English to French :

With the word "house" generate his French translation in a list : ['maison', 'demeure', 'rédisence']
After this fist loop, search the translation of an other word.
For instance, "good", which will output the translation in list format : ['bon', 'bien', 'bonne']
And so on until I've finished my translations.

At that time, I would like to do is to gathered all of list lists in one list, like this : [['maison', 'demeure', 'rédisence'], ['bon', 'bien', 'bonne']]
But I didn't succeed to do that... I've tried so many way that I've forgotten what I've tried lol ^^' can anyone help me please ? :)
What my script does, is only printing the list of the last word translated but I would like to print all of them in one list like above :/

My piece of code here :
Please be indulgent with me, I'm new in programming and I've done all of this with Youtube and Google ^^'
Thank you very much :)
I think you want a split() on line 34, not a strip(), but it would be helpful to see some of the output you are getting with the above code.
It print me this (dutch to french):

Until line 37 it works as I expect it to work. But as a output I would like to have his :

But instead of what I expect, it print me only last loop... although I would like to gather all the loop outputs
Is gathered_list the final output? If so, you are resetting it every loop. You are doing an assignment on line 32, which is completely reseting it to the current list of words. Set gathered_list to [] before the loop, and then just append final_list to gathered_list each loop.
Thank you so much :D I've just removed the gathered_list out of the while loop and putted it above the loop like you said and at the end of the loop I had just to do gathered_list.append(final_list). I didn't expect it to be so simple hahaha I've spend so much time searching it on internet lol :p thank you again :)