このPython配列がある場合:
mac_tags = [ "global_rtgn", "global_mogn" ]
そして私はこのPython配列が欲しいです:
mac_tags = [ "global_rtgn", "global_rtgn", "global_mogn","global_mogn" ]
プログラムで作成するにはどうすればよいですか?
このPython配列がある場合:
mac_tags = [ "global_rtgn", "global_mogn" ]
そして私はこのPython配列が欲しいです:
mac_tags = [ "global_rtgn", "global_rtgn", "global_mogn","global_mogn" ]
プログラムで作成するにはどうすればよいですか?
new_mac_tags = []
for tag in mac_tags:
new_mac_tags += [tag, tag]
また
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']
[i for i in sorted(mac_tags+mac_tags)]
これはこれを行うためのより機能的な方法であり、純粋な慣用的なPythonコードではない可能性があることに注意してください。
data = [[s, s] for s in [ "global_rtgn", "global_mogn" ]]
data = sum (data, [])
print data