Jan-24-2017, 06:55 AM
if i have
x=['a','b','c','d','e','f']
how can i make duplicates in a list comprehension and get a result like:
['a','a','b','b','c','c','d','d','e','e','f','f']
i tried this and (as expected) it did not work:
x=['a','b','c','d','e','f']
how can i make duplicates in a list comprehension and get a result like:
['a','a','b','b','c','c','d','d','e','e','f','f']
i tried this and (as expected) it did not work:
Output:lt1/forums /home/forums 40> py3
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> x=['a','b','c','d','e','f']
>>> x
['a', 'b', 'c', 'd', 'e', 'f']
>>> [z z for z in x]
File "<stdin>", line 1
[z z for z in x]
^
SyntaxError: invalid syntax
>>> [z, z for z in x]
File "<stdin>", line 1
[z, z for z in x]
^
SyntaxError: invalid syntax
>>>
lt1/forums /home/forums 41>