Python程式設計基礎Task12

2021-10-10 01:12:31 字數 671 閱讀 8664

python自帶的open可以開啟指定文字編碼的檔案。

只需要傳入encoding函式即可

2.

length =

with

open

('test.txt'

,'r'

)as f:

for i in f:

print

(i) word = i.split(

' ')

del word[

len(word)-1

]#刪除換行符號

for i in

range

(len

(word)):

length[word[i]]=

len(word[i]

) rst =

max(length, key=length.get)

# 對比關鍵字為【字典的值】

print

(rst)

這是文字內容:

程式執行結果:

程式設計TASK1

1.實現可以動態擴容的陣列 思路 新建陣列的時候,將陣列的容量大小設定為乙個變數,如果陣列容量不夠的時候,可以將原來資料擴大原來的幾倍,進行擴容 也可以直接使用c 中的vector容器,不必考慮原陣列的大小,如果需要增加元素,直接v.pushback 即可 2.將兩個有序陣列合併成乙個有序陣列 思路...

python基礎 打卡task1

a 1type a b float a b 1.0 type b c 1.5type c d int c d 1 type d 2 整型 布林型 a 0type a b bool a type b c flase type c d int c type d 3 浮點型 布林型 a 1.5type a...

Python基礎知識 task1

一 環境搭建 1.anaconda環境配置 注意 此處的環境配置針對的是在安裝anaconda的過程中沒有勾選自動配置環境變數那項。上圖即為環境變數的配置,注意是前五項的更新 win10 2.anaconda的環境下配置python 3.直譯器 pycharm 的編譯 三 python基礎講解 1....