Python - Complete list of each writer, along with the acronym of each person (first letter of name and surname)

1

Based on the list of writers described below, I have to manually create a list where each element is a list of two elements, name and nickname .

Here's the list:

escritores = [['Pedro', 'Tamen'], ['Almeida', 'Garrett'], ['Camilo', 'Pessanha'], ['Almada', 'Negreiros'], ['Ibn', 'Bassam'], ['Antonio', 'Aleixo'], ['Ricardo', 'Reis'], ['Mario', 'Sá-Carneiro'], ['Mario', 'Cesariny'], ['Luis', 'Camões'], ['Miguel', 'Torga'], ['Natália', 'Correia'], ['Tolentino', 'Mendonça']]
 Os elementos referenciam-se do seguinte modo: 

Writers [0] [0] = 'Pedro', and writers [0] [1] = 'Tamen'

List of writers

Peter Tamen

Almeida Garrett

Camilo Pessanha

Almada Blacksmiths

Ibn Bassam

Antonio Aleixo

Ricardo Reis

Mario Sá-Carneiro

Mario Cesariny

Luis Camões

Michael Torga

Natalia Correia

Tolentino Mendonça

What I want to do is print on the screen the full name of each writer, along with the acronym of each person (first letter of the name and surname, PT for Pedro Tamen).

PT Pedro Tamen

...

...

My code:

escritores = [['Pedro', 'Tamen'], ['Almeida', 'Garrett'], ['Camilo', 'Pessanha'], ['Almada', 'Negreiros'], ['Ibn', 'Bassam'], ['Antonio', 'Aleixo'], ['Ricardo', 'Reis'], ['Mario', 'Sá-Carneiro'], ['Mario', 'Cesariny'], ['Luis', 'Camões'], ['Miguel', 'Torga'], ['Natália', 'Correia'], ['Tolentino', 'Mendonça']]
#print(escritores)

#letra = escritores[1:4]
#escritores [0][0] = 'Pedro', e escritores [0][1] = 'Tamen'

print (escritores[:] [:])

I'm not smart enough to get out of this !!

Any help please!?

Thanks,

    
asked by anonymous 02.05.2018 / 15:21

1 answer

1

If you already have the list of writers, to print the full name and acronym of each you can do:

escritores = [['Pedro', 'Tamen'], ['Almeida', 'Garrett'], ['Camilo', 'Pessanha'], ['Almada', 'Negreiros'], ['Ibn', 'Bassam'], ['Antonio', 'Aleixo'], ['Ricardo', 'Reis'], ['Mario', 'Sá-Carneiro'], ['Mario', 'Cesariny'], ['Luis', 'Camões'], ['Miguel', 'Torga'], ['Natália', 'Correia'], ['Tolentino', 'Mendonça']]
for nome, apel in escritores: # unpacking de cada elemento da lista, https://stackoverflow.com/questions/6967632/unpacking-extended-unpacking-and-nested-extended-unpacking
    print('{} {}, {}{}'.format(nome, apel, nome[0], apel[0]))

Output:

Pedro Tamen, PT
Almeida Garrett, AG
Camilo Pessanha, CP
Almada Negreiros, AN
Ibn Bassam, IB
Antonio Aleixo, AA
Ricardo Reis, RR
Mario Sá-Carneiro, MS
Mario Cesariny, MC
Luis Camões, LC
Miguel Torga, MT
Natália Correia, NC
Tolentino Mendonça, TM

DEMONSTRATION

    
02.05.2018 / 15:44