if I have this Python array:
mac_tags = [ "global_rtgn", "global_mogn" ]
And I want this Python array:
mac_tags = [ "global_rtgn", "global_rtgn", "global_mogn","global_mogn" ]
How might I create it programmatically?
if I have this Python array:
mac_tags = [ "global_rtgn", "global_mogn" ]
And I want this Python array:
mac_tags = [ "global_rtgn", "global_rtgn", "global_mogn","global_mogn" ]
How might I create it programmatically?
new_mac_tags = []
for tag in mac_tags:
new_mac_tags += [tag, tag]
or
from itertools import chain, izip
new_mac_tags = list(chain.from_iterable(izip(mac_tags, mac_tags)))
>>> [a for a in mac_tags for x in range(2)]
['global_rtgn', 'global_rtgn', 'global_mogn', 'global_mogn']
Please note that this is more of a functional way of doing this and may not be pure idiomatic python code.
data = [[s, s] for s in [ "global_rtgn", "global_mogn" ]]
data = sum (data, [])
print data