Dec-25-2021, 10:35 PM
(This post was last modified: Dec-25-2021, 10:42 PM by noahverner1995.)
(Dec-25-2021, 09:42 AM)ibreeden Wrote:(Dec-25-2021, 07:55 AM)noahverner1995 Wrote: Well, that would work indeed, but how can a program manage to get the data from the folders in the path provided into that linked list?Well, that is easy. You have done a good job. In line 24 (print(list_of_file_contents)
) you have all the data you need.
So just after "# Main method" you add a line to create the dictionary:
the_linked_list = {}... And after line "print(list_of_file_contents)" you fill the dictionary:
the_linked_list[path] = list_of_file_contentsThat should do it. You don't need the lines after "# Get files and add directory to LL".
And again: this is not a "linked list", it is a dictionary.
I see, I think I managed to deal with my problem using a dictionary, I rewrote the code for the case of wanting to apply it only in the current directory (where this program would be found).
import os # Main method the_dictionary_list = {} for subdir in os.listdir("."): if os.path.isdir(subdir): path = os.path.abspath(subdir) print(f'\u001b[45m{path}\033[0m') list_of_file_contents = os.listdir(path) print(f'\033[46m{list_of_file_contents}') the_dictionary_list[subdir] = list_of_file_contents print('\n') print('\033[1;37;40mThe dictionary list:\033[0m') for subdir in the_dictionary_list: print('\u001b[43m'+subdir+'\033[0m') for archivo in the_dictionary_list[subdir]: print(" ", archivo) print('\n') print(the_dictionary_list)In my case, the code above prints the following output:
Quote:Color
['Amarillo.png', 'Blanco.png', 'Rojirosado.png', 'Turquesa.png', 'Verde_oscuro.png', 'Zapote.png']
Cuerpo
['Cuerpo_cangrejo.png']
Fondo
['Oceano.png']
Ojos
['Antenas.png', 'Pico.png', 'Verticales.png']
Pinzas
['Pinzitas.png', 'Pinzotas.png', 'Pinzota_pinzita.png']
Puas
['Arena.png', 'Marron.png', 'Purpura.png', 'Verde.png']
the_dictionary_list:
{'Color': ['Amarillo.png', 'Blanco.png', 'Rojirosado.png', 'Turquesa.png', 'Verde_oscuro.png', 'Zapote.png'], 'Cuerpo': ['Cuerpo_cangrejo.png'], 'Fondo': ['Oceano.png'], 'Ojos': ['Antenas.png', 'Pico.png', 'Verticales.png'], 'Pinzas': ['Pinzitas.png', 'Pinzotas.png', 'Pinzota_pinzita.png'], 'Puas': ['Arena.png', 'Marron.png', 'Purpura.png', 'Verde.png']}
Now it's only left the linked list, If I manage to do it that way, I will post it here...