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

17번째 줄: 17번째 줄:
[[category: PHP]]
[[category: PHP]]
<source lang='PHP'>
<source lang='PHP'>
$array = array(1, "hello", 1, "world", "hello");
$array = array(1, 'hello', 1, 'world', 'hello');
print_r(array_count_values($array));
print_r(array_count_values($array));
// Array
// Array

2014년 8월 24일 (일) 22:15 판

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 }}