python - list 列表推导式

一、如有两个list,分别为:

a = [1,2,3,4,5,6]
b = ["a","b","c","d","e","f"]

用python来实现 ['a1', 'b2', 'c3', 'd4', 'e5', 'f6'] 的格式,如何实现呢?

下面我用列表推导式来实现
db = [str(x) +str(y) for x,y in zip(b,a)]
print(db)

 

 

二、实现对两个字符串进行拼接,然后进行以A -- >Z ,再 a-->z 的顺序排序

a = "awfesdafhjkcasadckjsdackjsadvcnksausafdsch"
b = "SufhwrifjiEIJFDIEJDIej"
list1 = list(a+b)
list2 = sorted(list1)
print(''.join(list2))

 



 

 

 

 


posted @ 2019-06-15 22:42  Test挖掘者  阅读(1209)  评论(0编辑  收藏  举报