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‘}
待续
时间: 2024-10-31 04:44:25