Created
May 8, 2015 12:23
-
-
Save a2chub/0ab1a4cda35f0ca2ea99 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#coding:utf-8 | |
org_arr = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] | |
seikai = """1,2,3 | |
4,5,6 | |
7,8,9 | |
""" | |
print 'オリジナル配列\n' + str(org_arr) | |
print '\n目標の形式\n' + str(seikai) | |
def conv_arr2csv(org_list): | |
tmp_all = [] | |
for i in org_list: # 1行ずつ取り出す | |
tmp_row = [] # 仮リストを初期化 | |
for ii in i: # 1カラムずつ取り出す | |
tmp_row.append(str(ii)) #文字にキャストし、仮リストに追記する | |
tmp_all.append(",".join(tmp_row)+"\n") #仮リストをコンマで接続し末尾に改行を追加 | |
return "".join(tmp_all) # リスト全体を空文字で接続 | |
def listC(tgt_arr): | |
print "\n".join([','.join([str(x) for x in i]) for i in tgt_arr]) | |
def main(): | |
listC(org_arr) | |
#print conv_arr2csv(org_arr) | |
if __name__ == '__main__': | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment