zoukankan      html  css  js  c++  java
  • python每次处理一个字符的三种方法

    python每次处理一个字符的三种方法


    a_string = "abccdea"
    
    print 'the first'
    for c in a_string:
        print ord(c)+1
    
        
    print "the second"    
    result = [ord(c)+1 for c in a_string]
    print result
    
    print "the thrid"
    
    def do_something(c):
        return ord(c)+1
    
    result = map(do_something ,a_string)
    print result
    


    打印出的结果:

    the first
    98
    99
    100
    100
    101
    102
    98
    the second
    [98, 99, 100, 100, 101, 102, 98]
    the thrid
    [98, 99, 100, 100, 101, 102, 98]
    


  • 相关阅读:
    hihocoder 1038
    hihocoder 1039
    poj 2774
    bzoj 4690&&4602
    poj 2417
    STL
    poj 1026
    poj 1064
    poj 1861(prim)
    poj 1129
  • 原文地址:https://www.cnblogs.com/james1207/p/3329044.html
Copyright © 2011-2022 走看看