As it happens, sometimes code works, but after a while you go back to your lines of code and you see how complicated is to get back to what you did, what that variable was there for, etc.
I tried to make more readeable the code I posted in the last post... and here it is.
The code takes the names from an external file. There is one name and surname for row, like these:
Agresta Lenza
Filomena Cesareo
Annarita Cortazzo
Pasqualina Amoresano
Tiziana Iuliano
Fortunata Mangia
Matteo Cavallo
Angela Imbriaco
Ortensia Russo
Marotta Sansone
Maurizio De Vita
Caputo Califano
Annarita Rambaldi
Sara Piciocchi
Marotta La Marca
Ida Franco
Giovanni Saturno
And now let's see the code to reverse surname with names.
I put the code to grab the names in the txt file... returning it as a list, of course. You must give an arg to the function: the name of the txt file, as we will see at the end.
Then I put the code to 'reverse' the name and surname in two functions. The first, up here, takes care of a 3 parts name that can have the case of 2 names or a surname made of "De" or "La" before the surname (those are the only type of names I have in my list of names in the txt file). Below we got the function that takes care of a 4 parts name.
I changed other parts in the code. I put the parts rearranged in a list called name. Then I appended to the "wholename" list a string that passes in the curly brackets the sigle values of the items with the format methods, a very clean method for combining strings and variables.
Ok, now this part is more readeable than before. The list is iterated and each name is divided in parts, if the parts are 3 it goes to the names3 function, if 4 to names4, otherwis it's the simpliest case of a 2 parts name that is handled in this function.
Then the wholename list is sorted (by surname this time) and the name are printed.
Finally... we use lista to memorize the list generated by grabNames function (passing the arg that is the name of the file with the names and surname of people in the list).
Then we create the wholename list (empty).
Then we call the main function surnameBeforeName passing as arg lista (the list of names) and the reordering will be done as we've seen just before.
This is the result:
0 ) Amoresano Pasqualina
1 ) Califano Caputo
2 ) Cavallo Matteo
3 ) Cesareo Filomena
4 ) Cortazzo Annarita
5 ) De Vita Maurizio
6 ) Franco Ida
7 ) Imbriaco Angela
8 ) Iuliano Tiziana
9 ) La Marca Marotta
10 ) Lenza Agresta
11 ) Mangia Fortunata
12 ) Piciocchi Sara
13 ) Rambaldi Annarita
14 ) Russo Ortensia
15 ) Sansone Marotta
16 ) Saturno Giovanni
I tried to make more readeable the code I posted in the last post... and here it is.
The code takes the names from an external file. There is one name and surname for row, like these:
Agresta Lenza
Filomena Cesareo
Annarita Cortazzo
Pasqualina Amoresano
Tiziana Iuliano
Fortunata Mangia
Matteo Cavallo
Angela Imbriaco
Ortensia Russo
Marotta Sansone
Maurizio De Vita
Caputo Califano
Annarita Rambaldi
Sara Piciocchi
Marotta La Marca
Ida Franco
Giovanni Saturno
And now let's see the code to reverse surname with names.
I put the code to grab the names in the txt file... returning it as a list, of course. You must give an arg to the function: the name of the txt file, as we will see at the end.
Then I put the code to 'reverse' the name and surname in two functions. The first, up here, takes care of a 3 parts name that can have the case of 2 names or a surname made of "De" or "La" before the surname (those are the only type of names I have in my list of names in the txt file). Below we got the function that takes care of a 4 parts name.
Ok, now this part is more readeable than before. The list is iterated and each name is divided in parts, if the parts are 3 it goes to the names3 function, if 4 to names4, otherwis it's the simpliest case of a 2 parts name that is handled in this function.
Then the wholename list is sorted (by surname this time) and the name are printed.
Finally... we use lista to memorize the list generated by grabNames function (passing the arg that is the name of the file with the names and surname of people in the list).
Then we create the wholename list (empty).
Then we call the main function surnameBeforeName passing as arg lista (the list of names) and the reordering will be done as we've seen just before.
This is the result:
0 ) Amoresano Pasqualina
1 ) Califano Caputo
2 ) Cavallo Matteo
3 ) Cesareo Filomena
4 ) Cortazzo Annarita
5 ) De Vita Maurizio
6 ) Franco Ida
7 ) Imbriaco Angela
8 ) Iuliano Tiziana
9 ) La Marca Marotta
10 ) Lenza Agresta
11 ) Mangia Fortunata
12 ) Piciocchi Sara
13 ) Rambaldi Annarita
14 ) Russo Ortensia
15 ) Sansone Marotta
16 ) Saturno Giovanni
Comments
Post a Comment