일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- Java
- Google Spreadsheet
- Apache
- Python
- google apps script
- c#
- array
- SQL
- PySpark
- Kotlin
- Mac
- Google Excel
- PostgreSQL
- Excel
- list
- 파이썬
- Github
- PANDAS
- string
- dataframe
- hive
- Redshift
- Tkinter
- math
- django
- GIT
- matplotlib
- gas
- numpy
- Today
- Total
목록list (22)
달나라 노트
list.count(x) list에 count method를 적용시키면 count의 parameter로 전달된 값이 list 속에서 몇개가 존재하는지 세어줍니다. list_test = [1, 1, 2, 2, 2, 3, 3, 10, 5, 5, 5, 5, 8, 8, 7, 7, 'a', 'a', 'bb', 'bb', 'bb', '\n'] cnt_5 = list_test.count(5) # 1 cnt_a = list_test.count('a') # 2 cnt_line_break = list_test.count('\n') # 3 cnt_bb = list_test.count('bb') # 4 cnt_c = list_test.count('c') # 5 print(cnt_5) print(cnt_a) print(cnt_..
take 함수는 collection에서 원하는 개수의 요소만 골라 새로운 collection을 만듭니다. fun main() { var fruits = listOf("Apple", "Strawberry", "Tomato", "Watermelon", "Grape") fruits = fruits.take(3) println(fruits) } -- Result [Apple, Strawberry, Tomato] 위 예시를 보면 fruits list에 take(3)이라는 함수를 적용하고 있습니다. 그 결과는 fruits list의 가장 앞의 3개 요소만 있는 list가 만들어졌음을 알 수 있죠.
shuffled 함수는 collection의 요소들을 랜덤하게 재배열합니다. fun main() { var fruits = listOf("Apple", "Strawberry", "Tomato", "Watermelon", "Grape") fruits = fruits.shuffled() println(fruits) } -- Result [Strawberry, Tomato, Apple, Watermelon, Grape] fruits라는 list를 생성하고 shuffled를 적용시켜보았습니다. 그 결과를 보면 fruits의 요소들이 랜덤하게 재정렬된 것을 볼 수 있습니다. (따라서 이 결과는 위 코드를 실행할 때 마다 달라질 것입니다.)