๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

728x90

listcomprehension

1/11 ์ˆ˜ 1. tqdm in list comprehension / in pandas import pandas as pd import numpy as np from tqdm import tqdm # from tqdm.notebook import tqdm # Ver. 1 For Jupyter Notebook # from tqdm.auto import tqdm # Ver. 2 For Jupyter Notebook def process(token): return token['text'] l1 = [{'text': k} for k in range(5000)] l2 = [process(token) for token in tqdm(l1)] # tqdm in list comprehension #------------------.. ๋”๋ณด๊ธฐ
8/23 ํ™” 1. pass์™€ continue์˜ ์ฐจ์ด for i in range(5): if i % 2 == 0: pass # ์•„๋ฌด๊ฒƒ๋„ ํ•˜์ง€ ์•Š์Œ print(i) # 0 # 1 # 2 # 3 # 4 for i in range(5): if i % 2 == 0: continue # ํ•˜๋‹จ์˜ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•˜์ง€ ์•Š๊ณ  ๋„˜์–ด๊ฐ€ ์ƒ๋‹จ์˜ ๋ฐ˜๋ณต๋ฌธ์„ ๋งˆ์ € ์‹คํ–‰ํ•จ print(i) # 1 # 3 2. ๋ถ€๋™์†Œ์ˆ˜์ ์˜ ์˜ค์ฐจ ์ปดํ“จํ„ฐ์—์„œ ๋ถ€๋™์†Œ์ˆ˜์  ์ˆซ์ž๋“ค์€ 2์ง„ ๋ถ„์ˆ˜๋กœ ํ‘œํ˜„๋˜๊ธฐ์— ๊ฝค ๋งŽ์€ ๊ฐ’์€ ์ •ํ™•ํžˆ ํ‘œํ˜„๋  ์ˆ˜ ์—†๋‹ค. ๊ทธ๋ ‡๊ธฐ์— ์‚ฌ๋žŒ์ด ์ดํ•ดํ•˜๊ธฐ ์‰ฝ๊ฒŒ ์ž…๋ ฅํ•˜๋Š” 10์ง„ ๋ถ€๋™์†Œ์ˆ˜์  ์ˆซ์ž๋Š” 2์ง„ ๋ถ€๋™์†Œ์ˆ˜์  ์ˆซ์ž๋กœ ๊ทผ์‚ฌ ๋œ๋‹ค. ๋ถ€๋™์†Œ์ˆ˜์ ์˜ ์˜ค์ฐจ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด์„œ ์ž์ฃผ ์‚ฌ์šฉ๋˜๋Š” ํ•จ์ˆ˜๋Š” round()์™€ math ๋ชจ๋“ˆ์˜ math.isclose()๊ฐ€ ์žˆ๋‹ค. round(.. ๋”๋ณด๊ธฐ

728x90