文章詳情頁
python - 多維列表內(nèi)一部分字符串型轉(zhuǎn)換為整型
瀏覽:127日期:2022-06-30 15:53:58
問題描述
shell.txta1 b1 0.2 0a1 c1 0.8 0b1 c1 0.7 0a2 b2 1 0a2 d2 0.4 0d2 b2 0.6 0a1 a2 1 1a2 a1 0.1 1b1 b2 0.5 1b2 b1 0 1
with open(’shell.txt’) as f: lines = f.readlines()mylist = [line.strip().split() for line in lines]
由于txt數(shù)據(jù)加載后均為字符串型,現(xiàn)需要講后兩列轉(zhuǎn)換為整型,求大佬給些clean的方法,謝謝
問題解答
回答1:result = []for i in f: s = i.split() result.append(s[:-2]+map(lambda x: int(float(x)), ss[-2:]))print result
相關(guān)文章:
1. 數(shù)組按鍵值封裝!2. 關(guān)docker hub上有些鏡像的tag被標(biāo)記““This image has vulnerabilities””3. docker不顯示端口映射呢?4. Docker for Mac 創(chuàng)建的dnsmasq容器連不上/不工作的問題5. java - 阿里的開發(fā)手冊中為什么禁用map來作為查詢的接受類?6. docker安裝后出現(xiàn)Cannot connect to the Docker daemon.7. android - 百度地圖加載完成監(jiān)聽8. python - flask _sqlalchemy 能否用中文作為索引條件9. dockerfile - 我用docker build的時候出現(xiàn)下邊問題 麻煩幫我看一下10. nignx - docker內(nèi)nginx 80端口被占用
排行榜

熱門標(biāo)簽