kdy00963990
@kdy00963990
Reviews Written
11
Average Rating
5.0
Posts
Q&A
์ฐธ๊ณ ์ฝ๋ ์๋ฃ 7-StructuredConcurrency(102, 103์ค) ์คํ?
A์ฝ๋ func fetchAsyncLetTwoImages() async throws -> (UIImage, UIImage) { let start = Date() /// ๊ตฌ์กฐ์ ๋์์ฑ ์์ ์ ์์ฑ (ํ์ ์์ ์ ์์ฑ) async let image1 = try await fetchImage(num: 1) async let image2 = try await fetchImage(num: 2) let images = try await (image1, image2) print(Date().timeIntervalSince(start).formatted(.number.precision(.fractionLength(1)))) return images } B์ฝ๋ func fetchAsyncLetTwoImages() async throws -> (UIImage, UIImage) { let start = Date() /// ๊ตฌ์กฐ์ ๋์์ฑ ์์ ์ ์์ฑ (ํ์ ์์ ์ ์์ฑ) async let image1 = fetchImage(num: 1) async let image2 = fetchImage(num: 2) let images = try await (image1, image2) print(Date().timeIntervalSince(start).formatted(.number.precision(.fractionLength(1)))) return images }
- 0
- 3
- 43
Q&A
์ ๋ต ์ค๋ฅ
์ ๋ \n, ์ปด๋ง, ๋น์นธ ์ผ๋ก ๋๋ด๊ณ \n ์ผ๋ก ๋๋ ๊ฒฝ์ฐ ๋๋ถ๋ถ ํ ์นธ์ด ๋์ด์ ธ ์์ด์ ๋จ์ด์ ๋ฆฌ์คํธ์ ""์ด ์์๋ก ์กํ๋๋ค. ๊ทธ๋์ ๊ทธ๋ฅ ๋จ์ด ๋ฆฌ์คํธ์์ ""๋ฅผ ์ ๊ฑฐํ๊ณ ๋๋ 73์ด ๋์ค๋ค์.import re # ๋ฐฉ๋ฒ 1: regular expression ์ฌ์ฉ def how_many_words_in_a_text_file(path: str) -> (str, int): with open(path, "r", encoding="utf-8") as f: text = f.read() words = re.split(" |,|\n", text) words = [word for word in words if word != ""] return (words, len(words)) print(how_many_words_in_a_text_file("../source/22-1.txt")) --- ๊ฒฐ๊ณผ๊ฐ (['The', 'adjective', '"deep"', 'in', 'deep', 'learning', 'refers', 'to', 'the', 'use', 'of', 'multiple', 'layers', 'in', 'the', 'network.', 'Early', 'work', 'showed', 'that', 'a', 'linear', 'perceptron', 'cannot', 'be', 'a', 'universal', 'classifier', 'but', 'that', 'a', 'network', 'with', 'a', 'nonpolynomial', 'activation', 'function', 'with', 'one', 'hidden', 'layer', 'of', 'unbounded', 'width', 'can.', 'Deep', 'learning', 'is', 'a', 'modern', 'variation', 'which', 'is', 'concerned', 'with', 'an', 'unbounded', 'number', 'of', 'layers', 'of', 'bounded', 'size', 'which', 'permits', 'practical', 'application', 'and', 'optimized', 'implementation', 'while', 'retaining', 'theoretical'], 73) # ๋ฐฉ๋ฒ2 : ์ ๊ทํํ์ ์์ด replace์ split์ผ๋ก def number_of_words_in_the_text(path: str) -> (str, int): with open(path, 'r', encoding="utf-8") as f: text = f.read() text = text.replace(",", " ").replace("\n", " ") words = text.split(" ") words = [word for word in words if word != ""] return (words, len(words)) print(number_of_words_in_the_text("../source/22-1.txt")) --- ๊ฒฐ๊ณผ๊ฐ (['The', 'adjective', '"deep"', 'in', 'deep', 'learning', 'refers', 'to', 'the', 'use', 'of', 'multiple', 'layers', 'in', 'the', 'network.', 'Early', 'work', 'showed', 'that', 'a', 'linear', 'perceptron', 'cannot', 'be', 'a', 'universal', 'classifier', 'but', 'that', 'a', 'network', 'with', 'a', 'nonpolynomial', 'activation', 'function', 'with', 'one', 'hidden', 'layer', 'of', 'unbounded', 'width', 'can.', 'Deep', 'learning', 'is', 'a', 'modern', 'variation', 'which', 'is', 'concerned', 'with', 'an', 'unbounded', 'number', 'of', 'layers', 'of', 'bounded', 'size', 'which', 'permits', 'practical', 'application', 'and', 'optimized', 'implementation', 'while', 'retaining', 'theoretical'], 73)
- 0
- 2
- 252




