-1

As a result of a function I have a list with the elements inside another list, and I would like to extract this elements to have a unique list.

This is the list I have:

[['word'], ['word'], ['word'], ['word']]

This is the list I would like to have:

['word', 'word', 'word', word']

How can I do this?

Igor F.
  • 2,649
  • 2
  • 31
  • 39

2 Answers2

0
list = [['word'], ['word'], ['word']]
output = []
for entry in list:
    for word in entry:
        output.append(word)
print(output)
Stephen
  • 8,508
  • 12
  • 56
  • 96
Ozballer31
  • 413
  • 1
  • 5
  • 14
0
import itertools

result = list(itertools.chain(*original_list))
toothywalrus
  • 129
  • 2
  • 6
  • 1
    I'm pretty sure itertools offers a method specifically for this: `itertools.chain.from_iterable(original_list)` – AMC Jan 18 '20 at 22:14