标签:range env ble turn 处理 nbsp row int data
#!/usr/bin/env python3.5
2 #coding:utf-8
3 #
4 # 这个项目主要目的是字符串的处理,简单格式化输出
5 tableData = [[‘apples‘,‘oranges‘,‘cherries‘,‘banana‘],
6 [‘Alice‘,‘Bob‘,‘Carol‘,‘David‘],
7 [‘dogs‘,‘cats‘,‘moose‘,‘goose‘]]
8 # 要求输出如下:
9 # apples Alice dogs
10 # dranges Bob cats
11 # cherries Carol moose
12 # banana David goose
13
14 #没能输出上图的格式,输出格式全部是向右对齐的
15 def printTable(data):
16 str_data = ‘‘
17 col_len = []
18 for row in range(0,len(data[0])):
19 for col in range(0,len(data)):
20 col_len.append(len(data[col][row]))
21 max_col_len = max(col_len)
22 print("列表各元素长度为:")
23 print(col_len)
24 print("列表中最大值为:",max_col_len)
25 for row in range(0,len(data[0])):
26 for col in range(0,len(data)):
27 print(data[col][row].rjust(max_col_len),end=‘‘)
28 print()
29 return str_data
30 f_data = printTable(tableData)
31 print(f_data)
标签:range env ble turn 处理 nbsp row int data
原文地址:http://www.cnblogs.com/mfyang/p/6663495.html