I have this list :
listOfWords = ["this","is","a","list","of","words"]
and I need to have [this is a list of words]
, with a List comprehension.
Asked
Active
Viewed 152 times
-2

Cache Staheli
- 3,510
- 7
- 32
- 51

iratxe
- 87
- 9
-
2you want a list containing a single string? `[" ".join(listOfWords)]` – Greg Jun 23 '16 at 17:10
-
What is the output that you want? `['this is a list of words']`? – mgilson Jun 23 '16 at 17:10
-
Yes I will [" ".join(listOfWords)] – iratxe Jun 23 '16 at 17:25
-
and the output ['this is a list of words'] – iratxe Jun 23 '16 at 17:27
1 Answers
0
You mean a list with a single string item?
>>> [' '.join(["this","is","a","list","of","words"])]
['this is a list of words']

bakkal
- 54,350
- 12
- 131
- 107
-
-
1Python is Python everywhere, which IDE or console doesn't really matter :P – bakkal Jun 23 '16 at 17:13
-
-
If you wonder about `>>>`, no you don't type that in, you just type `[' '.join(["this","is","a","list","of","words"])]` – bakkal Jun 23 '16 at 17:16
-
sorry ... I have to write : listOfWords = ["this","is","a","list","of","words"] ls = listOfWords [' '.join(ls)] print ls And I come ['this', 'is', 'a', 'list', 'of', 'words'] , sorry I am new in Python ... – iratxe Jun 23 '16 at 17:17