Henu
개발냥발
Henu
전체 방문자
오늘
어제
  • 분류 전체보기 (411)
    • DevOps (52)
      • Kubernetes (19)
      • Docker (14)
      • AWS (3)
      • Nginx (4)
      • Linux (4)
      • ArgoCD (1)
      • CN (2)
      • NATS (0)
      • Git (5)
    • Back-End (30)
      • Django (18)
      • Spring (5)
      • JPA (1)
      • MSA (5)
    • CS (87)
      • SystemSoftware (20)
      • OS (25)
      • Computer Architecture (16)
      • Network (23)
      • Database (2)
    • Lang (21)
      • Java (9)
      • Python (4)
      • C# (8)
    • Life (12)
    • 블록체인 (2)
    • Algorithm (204)
      • BOJ (160)
      • 프로그래머스 (19)
      • LeetCode (4)
      • SWEA (1)
      • 알고리즘 문제 해결 전략 (8)
      • DS, algorithms (7)
      • Checkio (5)
    • IT (2)

블로그 메뉴

  • GitHub
  • 글쓰기
  • 관리자

공지사항

  • Free!

인기 글

태그

  • docker
  • Kubernetes
  • Network
  • django
  • 프로그래머스
  • 백트래킹
  • boj
  • DFS
  • 다이나믹 프로그래밍
  • BFS

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
Henu

개발냥발

Algorithm/Checkio

[Checkio] Scientific Expedition. Sum by Type

2020. 6. 17. 01:17

You have a list. Each value from that list can be either a string or an integer. Your task here is to return two values. The first one is a concatenation of all strings from the given list. The second one is a sum of all integers from the given list.

Input: An array of strings ans integers

Output: A list or tuple

 

1
2
3
4
5
6
7
8
9
def sum_by_types(items: list) -> Tuple[str, int]:
    ssum = 0
    string = ''
    for e in items:
        if type(e) == str: #isinstance(e, str)
            string+=e
        elif type(e) == int: #isinstance(e, int)
            ssum += e
    return (string, ssum)
cs

어렵지 않은 문제였는데 하나 배워간게 있어서 기록한다

5, 7번째 줄 if type(e) == str 과 if type(e) == int 는

if isinstance(e, str) 과 if isinstance(e, int) 로 바꿀 수 있다

 

isinstance(object, class<type>)

object의 자료형과 비교하고자 하는 자료형이 같으면 True, 다르면 False를 반환한다

'Algorithm > Checkio' 카테고리의 다른 글

[Checkio] Electronic station. Surjection Strings  (0) 2020.06.11
[Checkio] Electronic station. Digits Multiplication  (0) 2020.06.09
[Checkio] HOME. Bigger Price  (0) 2020.06.09
[Checkio] HOME. Sort Array by Element Frequency  (0) 2020.06.08
    'Algorithm/Checkio' 카테고리의 다른 글
    • [Checkio] Electronic station. Surjection Strings
    • [Checkio] Electronic station. Digits Multiplication
    • [Checkio] HOME. Bigger Price
    • [Checkio] HOME. Sort Array by Element Frequency

    티스토리툴바