| トップページ | Python 標準ドキュメント | 事例集 | アーティクル | リンク集 | ダウンロード | サイトマップ | |
![]() |
![]() |
|
お題:9 expand.pyお題7のcompress.pyで圧縮した結果を入力し、元の状態に展開して出力するプログラムを作成してください。 VED03370 at nifty.ne.jpさんのお答え
def inflate(infile, outfile):
head=infile.read(1)
while head:
if head==chr(0):
char=infile.read(1)
times=ord(infile.read(1))
outfile.write(char*times)
else:
outfile.write(infile.read(ord(head)))
head=infile.read(1)
if __name__=='__main__':
import sys
inflate(sys.stdin,sys.stdout)
|
|
|
|
|
|
また、日本Pythonユーザ会はサイト内のコンテンツに他のプログラミング言語からの乗り換えを誘発する恐れのある表現が多々あることを認め、予めお詫び申し上げます。 |