いくつかの処理方法のPythonのリスト

  • 機能の使用状況をマッピングします。
ss = map(str,range(3))
# ['1','2','3']
ii = map(int,ss)
# [1,2,3]
  • ラムダ関数の使用法:
numbers = [72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33]
print(sum(map(lambda x: x+10, numbers)))
  • リストの使用サイクル
numbers = [72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33]
[x for x in numbers if x>100]
# [101, 108, 108, 111, 119, 111, 114, 108]
  • 総合利用:
    TXTファイルがロードされている:
    TXTファイルを模式的に:
1 2 32
1 3 46
1 4 50
1 5 57
1 6 57
1 7 32
1 8 51

コード:

x= [ map(lambda x: int(x), x.split(' ')) for x in open('1.txt', 'r').read().split('\n')[1:-1]]
# x:
#[(1, 2, 32), (1, 3, 46), (1, 4, 50), (1, 5, 57), (1, 6, 57), (1, 7, 32), (1, 8, 51)]
公開された36元の記事 ウォンの賞賛0 ビュー20000 +

おすすめ

転載: blog.csdn.net/weixin_38102912/article/details/85267576