1. 程式人生 > >python3對序列求絕對值

python3對序列求絕對值

http://www.cnblogs.com/itdyb/p/5731804.html

    一開始我是這樣寫的,據說這樣寫python2是可以的: myList = [-1,2,-3,4,-5,6]
absList = map(abs, myList)                                                    
print(absList) 但是在python3中出錯了 >>>map object at 0x000000001470D208 所以改成了
myList = [-1,2,-3,4,-5,6]
absList = map(abs, myList)       #對於Python3.x需要用list函式對map的返回值轉換為列表
print(list(absList))   >>>[1, 2, 3, 4, 5, 6]   完美解決