"함수 array count values()"의 두 판 사이의 차이

26번째 줄: 26번째 줄:
// )
// )
</source>
</source>
==Python==
[[category: Python]]
<source lang='Python'>
import collections
lst = [1, 'hello', 1, 'world', 'hello']
print( collections.Counter(lst) )
# Counter({1: 2, 'hello': 2, 'world': 1})
</source>
==같이 보기==
==같이 보기==
*[[array_unique]]
*[[array_unique]]

2014년 8월 21일 (목) 15:11 판

uniq -c
array_count_values

1 Bash

ARR=(1 "hello" 1 "world" "hello")
for VALUE in "${ARR[@]}"; do
	echo $VALUE
done | sort | uniq -c
#      2 1
#      2 hello
#      1 world

2 PHP

$array = array(1, "hello", 1, "world", "hello");
print_r(array_count_values($array));
// Array
// (
//     [1] => 2
//     [hello] => 2
//     [world] => 1
// )

3 Python

import collections
lst = [1, 'hello', 1, 'world', 'hello']
print( collections.Counter(lst) )
# Counter({1: 2, 'hello': 2, 'world': 1})

4 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}