카타 7급 Most common first

1 Python[ | ]

def most_common(s):
    return ''.join(sorted(s, key = s.count, reverse = True))
from collections import Counter
def most_common(s):
    count = Counter(s)
    return ''.join(sorted(s, key=lambda c: -count[c]))
from collections import Counter
def most_common(s):
    c = Counter(s)
    return ''.join(sorted(s, key=lambda x: c[x], reverse=1))

2 R[ | ]

most_common <- function(s){
  v = unlist(strsplit(s,""))
  t = table(v)
  a = c()
  for( num in sort(unique(t),decreasing=TRUE) ) {
    a = append(a, v[v %in% names(t[t==num])])
  }
  paste(a, collapse="")
}
most_common <- function(s){
  sfact <- factor(substring(s, 1:nchar(s), 1:nchar(s)))
  paste(sfact[order(sapply(sfact, function(x) summary(sfact)[[x]]), decreasing = TRUE)], collapse = "")
}
most_common <- function(s){
  v = unlist(strsplit(s,""))
  c = sapply(seq_along(v), function(x) {sum(v[]==v[x])})
  paste(v[order(c,decreasing=TRUE)], collapse="")
}
most_common <- function(s){
  v <- unlist(strsplit(s, NULL))
  t <- table(v)
  v2 <- sapply(v, function(x) t[[x]], USE.NAMES=FALSE)
  paste(v[order(v2,decreasing=TRUE)], collapse="")
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}