๋กœ์ผ“๐Ÿพ
article thumbnail
[Python] Counter ๋ชจ๋“ˆ ์‚ฌ์šฉ๋ฒ• feat. ์นด์นด์˜ค ํŠœํ”Œ

ํŒŒ์ด์ฌ์—๋Š” ์ •๋ง ์œ ์šฉํ•œ ํ•จ์ˆ˜๊ฐ€ ๋งŽ์Šต๋‹ˆ๋‹ค. ๊ทธ ์ค‘ Counter ๋Š” ์ œ๊ฐ€ ์ƒ๊ฐํ•˜๊ธฐ์— ๊ฐ€์žฅ ์œ ์šฉํ•œ ํ•จ์ˆ˜ ์ค‘์— ํ•˜๋‚˜๋ผ๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฒˆ ๊ธ€์—์„œ๋Š” Collections ๋ชจ๋“ˆ ์ค‘ ํ•˜๋‚˜์ธ Counter ํ•จ์ˆ˜์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด๊ณ  2019 ์นด์นด์˜ค ๊ฒจ์šธ ์ธํ„ด์‰ฝ ํŠœํ”Œ ์— ๋ฐ”๋กœ ์ ์šฉํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿผ ๋ ›์ธ ๋‘๋”์ฝ”๋“œ! Collections ์˜ Counter() Counter ๋Š” ๋ฆฌ์ŠคํŠธ๋‚˜ ๋ฌธ์ž์—ด์˜ ๊ฐฏ์ˆ˜๋ฅผ dict ํƒ€์ž…์œผ๋กœ ๋ฐ˜ํ™˜ํ•ด์ฃผ๋Š” ํ•จ์ˆ˜์ž…๋‹ˆ๋‹ค. ๋ง๋กœ ๋ฐฑ๋ฒˆ ์„ค๋ช…ํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค ํ•œ๋ฒˆ์˜ ์˜ˆ์ œ๊ฐ€ ๋ณด๋Š” ๊ฒƒ์ด ๋” ์ข‹๊ฒ ์ฃ ? Counter(["I", "am", "Iron", "man", "!", "!"]) # Counter({'!': 2, 'I': 1, 'am': 1, 'Iron': 1, 'man': 1}) Counter(["I", "am", "..

article thumbnail
[Python] re ๋ชจ๋“ˆ ์‚ฌ์šฉ๋ฒ• feat. [3์ฐจ] ํŒŒ์ผ๋ช… ์ •๋ ฌ

ํŒŒ์ด์ฌ์—์„œ ๋ฌธ์ž์—ด์„ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ•์€ ์—ฌ๋Ÿฌ๊ฐ€์ง€๊ฐ€ ์žˆ์ฃ . ๊ทธ ์ค‘ ์ •๊ทœํ‘œํ˜„์‹์„ ์ด์šฉํ•˜๋ฉด ์ข€ ๋” ๋‹ค์–‘ํ•˜๊ณ  ์‰ฝ๊ฒŒ ์ฒ˜๋ฆฌ๋ฅผ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ž˜์„œ ์ด๋ฒˆ ๊ธ€์—์„œ๋Š” ํŒŒ์ด์ฌ์—์„œ ์œ ์šฉํ•œ ๋ชจ๋“ˆ ์ค‘ ์ •๊ทœ์‹์„ ์ฒ˜๋ฆฌํ•ด์ฃผ๋Š” re ๋ชจ๋“ˆ์„ ์ด์šฉํ•ด์„œ ๋ฌธ์ž์—ด์„ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ฐ€์žฅ ๋งˆ์ง€๋ง‰์—” ๋ฐฐ์šด๊ฑธ ํ† ๋Œ€๋กœ ์นด์นด์˜ค ๋ฌธ์ œ์ธ [3์ฐจ] ํŒŒ์ผ๋ช… ์ •๋ ฌ์— ์ ์šฉํ•ด๋ณด๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿผ ๋ ›์ธ ๋‘๋”์ฝ”๋“œ! re ๋ชจ๋“ˆ์˜ ํ•จ์ˆ˜๋“ค re ๋ชจ๋“ˆ์—๋Š” ๋‹ค์–‘ํ•œ ํ•จ์ˆ˜๋“ค์ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค. ๊ทธ ์ค‘ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ํ’€์ด์— ์œ ์šฉํ•  ๊ฒƒ ๊ฐ™์€ ํ•จ์ˆ˜๋“ค์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. search match fullmatch findall finditer sub subn split search() ๋ฌธ์ž์—ด์—์„œ ํŒจํ„ด์ด ์ผ์น˜ํ•˜๋Š” ์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. print(re.search("A", "..

profile on loading

Loading...