본문으로 건너뛰기
cccskills
무료GitHub에 공개

python-scala-collections

Guide for translating Python collection operations to idiomatic Scala. Use when converting Python code that uses lists, dictionaries, sets, or involves collection transformations like map, filter, reduce, sorting, and aggregations.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(1)

  • SKILL.md6.2 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Python to Scala Collections Translation

Collection Creation

Lists

# Python
empty = []
nums = [1, 2, 3]
repeated = [0] * 5
from_range = list(range(1, 11))
// Scala
val empty = List.empty[Int]  // or List[Int]()
val nums = List(1, 2, 3)
val repeated = List.fill(5)(0)
val fromRange = (1 to 10).toList

Dictionaries → Maps

# Python
empty = {}
person = {"name": "Alice", "age": 30}
from_pairs = dict([("a", 1), ("b", 2)])
// Scala
val empty = Map.empty[String, Int]
val person = Map("name" -> "Alice", "age" -> 30)
val fromPairs = List(("a", 1), ("b", 2)).toMap

Sets

# Python
empty = set()
nums = {1, 2, 3}
from_list = set([1, 2, 2, 3])
// Scala
val empty = Set.empty[Int]
val nums = Set(1, 2, 3)
val fromList = List(1, 2, 2, 3).toSet

Transformation Operations

Map

# Python
doubled = [x * 2 for x in nums]
doubled = list(map(lambda x: x * 2, nums))
// Scala
val doubled = nums.map(_ * 2)
val doubled = nums.map(x => x * 2)

Filter

# Python
evens = [x for x in nums if x % 2 == 0]
evens = list(filter(lambda x: x % 2 == 0, nums))
// Scala
val evens = nums.filter(_ % 2 == 0)
val evens = nums.filter(x => x % 2 == 0)

Reduce/Fold

# Python
from functools import reduce
total = reduce(lambda a, b: a + b, nums)
total = sum(nums)
product = reduce(lambda a, b: a * b, nums, 1)
// Scala
val total = nums.reduce(_ + _)
val total = nums.sum
val product = nums.foldLeft(1)(_ * _)
// Use foldLeft when you need an initial value

FlatMap

# Python
nested = [[1, 2], [3, 4]]
flat = [x for sublist in nested for x in sublist]
// Scala
val nested = List(List(1, 2), List(3, 4))
val flat = nested.flatten
// or with transformation:
val flat = nested.flatMap(identity)

Common Operations

Length/Size

PythonScala
len(lst)lst.length or lst.size
len(dct)map.size

Access

PythonScala
lst[0]lst(0) or lst.head
lst[-1]lst.last
lst[1:3]lst.slice(1, 3)
lst[:3]lst.take(3)
lst[3:]lst.drop(3)
dct["key"]map("key") (throws if missing)
dct.get("key")map.get("key") (returns Option)
dct.get("key", default)map.getOrElse("key", default)

Membership

# Python
if x in lst: ...
if key in dct: ...
// Scala
if (lst.contains(x)) ...
if (map.contains(key)) ...

Concatenation

# Python
combined = list1 + list2
merged = {**dict1, **dict2}
// Scala
val combined = list1 ++ list2
val merged = map1 ++ map2

Sorting

# Python
sorted_list = sorted(items)
sorted_desc = sorted(items, reverse=True)
sorted_by_key = sorted(items, key=lambda x: x.name)
items.sort()  # in-place
// Scala
val sortedList = items.sorted
val sortedDesc = items.sorted(Ordering[Int].reverse)
val sortedByKey = items.sortBy(_.name)
// Note: Scala collections are immutable by default, no in-place sort

Grouping

# Python
from itertools import groupby
from collections import defaultdict

# Group by key
grouped = defaultdict(list)
for item in items:
    grouped[item.category].append(item)
// Scala
val grouped = items.groupBy(_.category)
// Returns Map[Category, List[Item]]

Aggregations

# Python
total = sum(nums)
minimum = min(nums)
maximum = max(nums)
average = sum(nums) / len(nums)
// Scala
val total = nums.sum
val minimum = nums.min
val maximum = nums.max
val average = nums.sum.toDouble / nums.length

Finding Elements

# Python
first_even = next((x for x in nums if x % 2 == 0), None)
all_evens = all(x % 2 == 0 for x in nums)
any_even = any(x % 2 == 0 for x in nums)
// Scala
val firstEven = nums.find(_ % 2 == 0)  // Returns Option[Int]
val allEvens = nums.forall(_ % 2 == 0)
val anyEven = nums.exists(_ % 2 == 0)

Zipping

# Python
pairs = list(zip(list1, list2))
indexed = list(enumerate(items))
// Scala
val pairs = list1.zip(list2)
val indexed = items.zipWithIndex

Dictionary/Map Operations

# Python
keys = list(dct.keys())
values = list(dct.values())
items = list(dct.items())

for key, value in dct.items():
    process(key, value)

# Update
dct["new_key"] = value
updated = {**dct, "new_key": value}
// Scala
val keys = map.keys.toList
val values = map.values.toList
val items = map.toList  // List[(K, V)]

for ((key, value) <- map) {
  process(key, value)
}

// Update (creates new map, immutable)
val updated = map + ("new_key" -> value)
val updated = map.updated("new_key", value)

Mutable vs Immutable

Python collections are mutable by default. Scala defaults to immutable.

# Python - mutable
lst.append(4)
lst.extend([5, 6])
dct["key"] = value
// Scala - immutable (creates new collection)
val newList = lst :+ 4
val newList = lst ++ List(5, 6)
val newMap = map + ("key" -> value)

// Scala - mutable (when needed)
import scala.collection.mutable
val mutableList = mutable.ListBuffer(1, 2, 3)
mutableList += 4
mutableList ++= List(5, 6)

enum type

Use UPPERCASE for enum and constant names in Scala (same as in Python) E.g.

class TokenType(Enum):
    STRING = "string"
    NUMERIC = "numeric"
    TEMPORAL = "temporal"
    STRUCTURED = "structured"
    BINARY = "binary"
    NULL = "null"
object BaseType {
  case object STRING extends BaseType { val value = "string" }
  case object NUMERIC extends BaseType { val value = "numeric" }
  case object TEMPORAL extends BaseType { val value = "temporal" }
  case object STRUCTURED extends BaseType { val value = "structured" }
  case object BINARY extends BaseType { val value = "binary" }
}

Do not use PascalCase. E.g. the following is against the principle:

object BaseType {
  case object String extends BaseType { val value = "string" }
}

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Perform various data analysis on SEC 13-F and obtain some insights of fund activities such as number of holdings, AUM, and change of holdings between two quarters.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

benchflow-ai/skillsbench1.9천2026년 10월 13일 업데이트

AC branch pi-model power flow equations (P/Q and |S|) with transformer tap ratio and phase shift, matching `acopf-math-model.md` and MATPOWER branch fields. Use when computing branch flows in either direction, aggregating bus injections for nodal balance, checking MVA (rateA) limits, computing branch loading %, or debugging sign/units issues in AC power flow.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

benchflow-ai/skillsbench1.9천2026년 10월 13일 업데이트

Redact text from PDF documents for blind review anonymization

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

benchflow-ai/skillsbench1.9천2026년 10월 13일 업데이트

Use when checking simplified ADA-derived plan-view bathroom accessibility constraints such as turning space, door clear width, toilet centerline, grab bars, and lavatory knee/toe clearance.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

benchflow-ai/skillsbench1.9천2026년 10월 13일 업데이트

Analyze failed GitHub Action jobs for a pull request.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

benchflow-ai/skillsbench1.9천2026년 10월 13일 업데이트

Use when extracting plan-view architectural geometry from DXF files with semantic CAD layers, especially when outputs must normalize rooms, doors, fixtures, clearances, and grab bars into machine-checkable JSON.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

benchflow-ai/skillsbench1.9천2026년 10월 13일 업데이트

benchflow-ai의 스킬 모두 보기

이 스킬의 문제 신고