Is it possible to make a letter range in python?

前端 未结 8 1543
误落风尘
误落风尘 2021-01-02 17:23

Is there a way to do a letter range in python like this:

for x in range(a,h,)
8条回答
  •  隐瞒了意图╮
    2021-01-02 18:02

    import string
    
    def letter_range(f,l,al = string.ascii_lowercase):
        for x in al[al.index(f):al.index(l)]:
            yield x
    
    print ' '.join(letter_range('a','h'))
    

    result

    a b c d e f g
    

提交回复
热议问题