2018年3月29日 星期四

[ Python 常見問題 ] How do I iterate through the alphabet in Python?

Source From Here 
Question 
As title. How do I iterate a-z without creating my own list of chars? 

How-To 
You can use string.ascii_lowercase which is simply a convenience string of lowercase letters: 
>>> from string import ascii_lowercase 
>>> ascii_lowercase 
'abcdefghijklmnopqrstuvwxyz' 
>>> for c in ascii_lowercase: 
... print('Char {}'.format(c)) 
... 
Char a 
Char b 
... 
Char z


沒有留言:

張貼留言

[ JS 常見問題 ] Time difference in Nodejs?

Source From   Here   Question   Im trying to figure out a way to   get the time difference in seconds between two dates . For example, diff...