편집을 취소할 수 있습니다. 이 편집을 되돌리려면 아래의 바뀐 내용을 확인한 후 게시해주세요.
최신판 | 당신의 편집 | ||
5번째 줄: | 5번째 줄: | ||
==Bash== | ==Bash== | ||
[[category: Bash]] | [[category: Bash]] | ||
< | <source lang='Bash'> | ||
ARR=(1 "hello" 1 "world" "hello") | ARR=(1 "hello" 1 "world" "hello") | ||
for VALUE in "${ARR[@]}"; do | for VALUE in "${ARR[@]}"; do | ||
echo $VALUE | echo $VALUE | ||
done | sort | uniq -c | done | sort | uniq -c | ||
</ | # 2 1 | ||
# 2 hello | |||
# 1 world | |||
</source> | |||
==POSIX Shell== | ==POSIX Shell== | ||
< | <source lang='Bash'> | ||
ARR="1 hello 1 world hello" | ARR="1 hello 1 world hello" | ||
for VALUE in $ARR | for VALUE in $ARR | ||
19번째 줄: | 22번째 줄: | ||
echo $VALUE | echo $VALUE | ||
done | sort | uniq -c | done | sort | uniq -c | ||
</ | # 2 1 | ||
# 2 hello | |||
# 1 world | |||
</source> | |||
==C== | ==C== | ||
27번째 줄: | 33번째 줄: | ||
==PHP== | ==PHP== | ||
[[category: PHP]] | [[category: PHP]] | ||
<source lang='PHP'> | |||
< | $array = array(1, 'hello', 1, 'world', 'hello'); | ||
$ | print_r(array_count_values($array)); | ||
print_r(array_count_values($ | // Array | ||
</ | // ( | ||
// [1] => 2 | |||
// [hello] => 2 | |||
// [world] => 1 | |||
// ) | |||
</source> | |||
==Python== | ==Python== | ||
[[category: Python]] | [[category: Python]] | ||
< | <source lang='Python'> | ||
import collections | import collections | ||
lst = [1, 'hello', 1, 'world', 'hello'] | lst = [1, 'hello', 1, 'world', 'hello'] | ||
print( collections.Counter(lst) ) | print( collections.Counter(lst) ) | ||
</ | # Counter({1: 2, 'hello': 2, 'world': 1}) | ||
</source> | |||
==Perl== | ==Perl== | ||
[[category:Perl]] | [[category:Perl]] | ||
< | <source lang='Perl'> | ||
my %cnt; | my %cnt; | ||
my @lst = (1, 'hello', 1, 'world', 'hello'); | my @lst = (1, 'hello', 1, 'world', 'hello'); | ||
$cnt{$_}++ for @lst; | $cnt{$_}++ for @lst; | ||
print %cnt; | print %cnt; | ||
# 12hello2world1 | |||
</source> | |||
</ | |||
==SQL== | ==SQL== | ||
62번째 줄: | 67번째 줄: | ||
===MySQL=== | ===MySQL=== | ||
[[category: MySQL]] | [[category: MySQL]] | ||
< | <source lang='console'> | ||
mysql> SELECT * FROM array; | mysql> SELECT * FROM array; | ||
+-------+ | +-------+ | ||
74번째 줄: | 79번째 줄: | ||
+-------+ | +-------+ | ||
5 rows in set (0.00 sec) | 5 rows in set (0.00 sec) | ||
</ | </source> | ||
< | <source lang='console'> | ||
mysql> SELECT value, COUNT(*) FROM array GROUP BY value; | mysql> SELECT value, COUNT(*) FROM array GROUP BY value; | ||
+-------+----------+ | +-------+----------+ | ||
85번째 줄: | 90번째 줄: | ||
+-------+----------+ | +-------+----------+ | ||
3 rows in set (0.00 sec) | 3 rows in set (0.00 sec) | ||
</ | </source> | ||
==같이 보기== | ==같이 보기== | ||
*[[ | *[[array_unique]] | ||
*[[함수 array_count_value()]] | *[[함수 array_count_value()]] | ||
*[[함수 majority()]] | *[[함수 majority()]] |