1. 程式人生 > >python雜記

python雜記

int char style tuple ascii dict span 字典 col

1. ord

將char轉換為ascii碼

print ord(‘a‘)
97

2. zip

>>> x = [ord(‘a‘), ord(‘b‘)]
>>> y = [‘a‘, ‘b‘, ‘c‘]


>>> xy = zip(x,y)
>>> print xy
[(97, ‘a‘), (98, ‘b‘)]


>>> z = zip(*xy)
>>> print z
[(97, 98), (‘a‘, ‘b‘)]

3. dict

字典,可以將tuple的list轉為dict

>>> print dict(zip(x,y))
{97: ‘a‘, 98: ‘b‘}

待續

python雜記