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

Asked

Viewed 46 times

1

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

Here is 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] = 'Peter', and writers [0][1] = 'Tamen'

List of writers

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

What I want is to print on the screen the full name of each writer, along with the acronym of each person (first letter of 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 being smart enough to get out of this!!

Some help please!?

Thank you,

  • you are very close don’t give up! you just need a for loop! to scroll through each item in the list!!

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

  • 1

    I can’t thank you enough. Thank you

  • You’re welcome @Joaopeixotofernandes, we’re here for this, we all have questions

Browser other questions tagged

You are not signed in. Login or sign up in order to post.