How to transform a list [['a'], ['b']] into a string: ab

-1
quantidade = int(input())
lista = []
lista2 = []
lista3 = []
palavra =()
i = 0
while quantidade != len(lista):
    a = input()
    lista.append(a)
for x in lista:
    b = x.split()
    lista2.append(b)
for x in lista2:
    x[0] = int(x[0])
del(lista[0:quantidade - 1])
lista2.sort()
for x in lista2:
    del(x[0])
    lista3.append(x)
print(lista3)

Problem link: link

    
asked by anonymous 15.08.2018 / 01:36

2 answers

1

(Answering the title, because the rest did not understand anything, please edit and improve the question)

Starting from a list, we can concatenate its values in several ways like:

lista = ['o','l','a']

string = ''.join(lista)
string = ''.join([x for x in lista])
string = ''.join(map(lambda x: x, lista))

def concatena(lista):
    string = ''
    for x in lista:
        string += x
    return string    
string = concatena(lista)

>>> print(string)
ola

And we can even modify it if necessary:

string = ''.join([x.upper() for x in lista]) #ou .lower()

Complicating a little but not much, we can play with arrays. Now just get the matrix lists and apply a method above.

matriz = [['o'],['l'],['a']]

#string = ''.join(map(lambda lista: Algum_metodo_acima, matriz))
#string = ''.join([Algum_metodo_acima for lista in matriz])

string = ''.join(map(lambda lista: ''.join(lista), matriz))
string = ''.join([''.join(lista) for lista in matriz])

def concatena_matriz(matriz):
    string = ''
    for lista in matriz:
        for x in lista:
            string += x
    return string

string = concatena_matriz(matriz)

>>> print(string)
ola
    
15.08.2018 / 04:29
0

If I understand your question, you want to extract the data from a list and put it in string, if it is, there are several to do, one of them is using ListComps.

alfabeto = [['a'], ['b'], ['c']]

''.join([letras for lista in alfabeto 
                for letras in lista])
  

Output: 'abc'

    
16.08.2018 / 12:11