Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Lists in list for newbies
#1
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 :)
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
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
Reply
#4
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#5
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 :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  List all possibilities of a nested-list by flattened lists sparkt 1 915 Feb-23-2023, 02:21 PM
Last Post: sparkt
  user input values into list of lists tauros73 3 1,064 Dec-29-2022, 05:54 PM
Last Post: deanhystad
  returning a List of Lists nafshar 3 1,058 Oct-28-2022, 06:28 PM
Last Post: deanhystad
  Creating list of lists, with objects from lists sgrinderud 7 1,612 Oct-01-2022, 07:15 PM
Last Post: Skaperen
  What is a circular import? asked by a newbie of newbies ineuw 1 944 Sep-16-2022, 07:27 PM
Last Post: Gribouillis
  How to efficiently average same entries of lists in a list xquad 5 2,114 Dec-17-2021, 04:44 PM
Last Post: xquad
  sorting a list of lists by an element leapcfm 3 1,858 Sep-10-2021, 03:33 PM
Last Post: leapcfm
  behavior list of lists roym 5 2,087 Jul-04-2021, 04:43 PM
Last Post: roym
  List of lists - merge sublists with common elements medatib531 1 3,392 May-09-2021, 07:49 AM
Last Post: Gribouillis
  Sort List of Lists by Column Nju 1 11,155 Apr-13-2021, 11:59 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020