データ構造(Python)-チュートリアル


コロイド管

  • 튜플(Tuple):リストに似ているが変更不可
  • (『姜虎東』『朴賛浩』『李勇圭』『朴勝哲』『姜虎東』『金智恩』)
  • 変更(修正・削除等)できないもの
  • 数字、文字(列)、論理型などすべての基本データを同時に格納できる
  • その他コンテナデータ格納
  • # 튜플
    students = ('강호동', '박찬호', '이용규', '박승철', '강호동', '김지은')
    print(students)
    print(type(students))
    
    # students[0] = 'Test' # 변경 불가, 오류 발생
  • リストと同様に使用인덱스物品照会
  • # 인덱스
    students = ('강호동', '박찬호', '이용규', '박승철', '강호동', '김지은')
    print(students)
    print(students[0])
    print(students[1])
    print(students[2])
    
    # 오류 발생
    # print('없는 인덱스 : {}'.format(students[6])) 
  • 物品の有無を判断する
  • 아이템 in 튜플:釘に物があればTrue
  • 아이템 not in 튜플:tupleに項目がなければTrue
  • # 아이템 존재 유무 판단
    students = ('홍길동', '박찬호', '이용규', '박승철', '김지은')
    searchName = input('학생 이름 입력 : ')
    # in
    if searchName in students:
        print('in - {} 학생은 존재합니다.'.format(searchName))
    else:
        print('in - {} 학생은 존재하지 않습니다.'.format(searchName))
    print('='*35)
    # not in
    if searchName not in students:
        print('not in - {} 학생은 존재하지 않습니다.'.format(searchName))
    else:
        print('not in - {} 학생은 존재합니다.'.format(searchName))
  • len():グラフ長(アイテム数)の関数を返す
  • # len()
    students = ('홍길동', '박찬호', '이용규', '박승철', '김은지', '강호동')
    studentLength = len(students)
    print(students)
    print("len : {}".format(studentLength))

    けつごう

  • +(덧셈 연산자):2つの継ぎ手を接続(拡張)して新しい継ぎ手に戻す
  • グラフは値を変更できないのでマージできませんが、加算演算子は新しいグラフを返すので使用できます.
  • リストのextend、remove、appendなどは使用できません.
  • # +(덧셈 연산자)
    studentTuple1 = ('홍길동', '박찬호', '이용규')
    studentTuple2 = ('박승철', '김지은', '강호동')
    print(studentTuple1)
    print(studentTuple2)
    
    newStudents = studentTuple1 + studentTuple2
    print(newStudents)

    スムージング処理

  • [시작:종료:간격]:スタート<=n<終了の範囲を基準に、アイテムを選択できます.
  • グラフではプーリを使用してアイテムを変更できない
  • # 슬라이싱
    students = ('홍길동', '박찬호', '이용규', '박승철', '김은지', '강호동')
    print('1. {}'.format(students))
    # 1. ('홍길동', '박찬호', '이용규', '박승철', '김은지', '강호동')
    print('2. {}'.format(students[2:4]))
    # 2. ('이용규', '박승철')
    print('3. {}'.format(students[2:5:2]))
    # 3. ('이용규', '김은지')
    
    # 리스트의 아이템을 튜플 형식을 사용해 바꾸는 것은 가능하다
    students = ['홍길동', '박찬호', '이용규', '박승철', '김은지', '강호동']
    
    students[1:4] = ('park chanho', 'lee yonggyu', 'park seungcheol')
    # 타입은 여전히 리스트이다.
    print(students)
    print(type(students))
  • slice(시작, 종료, 간격)
  • students = ('홍길동', '박찬호', '이용규', '박승철', '김은지', '강호동')
    
    print('1. {}'.format(students))
    # 1. ('홍길동', '박찬호', '이용규', '박승철', '김은지', '강호동')
    print('2. {}'.format(students[slice(2,4)]))
    # 2. ('이용규', '박승철')
    print('3. {}'.format(students[slice(2,5,2)]))
    # 3. ('이용규', '김은지')

    リストとチュートリアル

  • リスト:アイテムの追加、変更、削除が可能.
  • トゥーフ:アイテムの追加、変更、削除はできません.
  • # 리스트 추가, 변경, 삭제 가능
    studnetList = ['홍길동', '박찬호', '이용규']
    print(studnetList)
    # 추가
    studnetList.append('강호동')
    print(studnetList)
    # 변경
    studnetList[2] = '유재석'
    print(studnetList)
    # 삭제
    studnetList.pop()
    print(studnetList)
    
    # 튜플 추가, 변경, 삭제 불가능
    studnetTuple = ('홍길동', '박찬호', '이용규')
    print(studnetTuple)
    # 추가 : 오류 발생
    # studnetTuple.append('강호동')
    # 변경 : 오류 발생
    # studnetTuple[2] = '유재석'
    # 삭제 : 오류 발생
    # studentTuple.pop()
  • トゥープは宣言時に括弧を省略できる.
  • リストは宣言時に括弧は省略できない.
  • # 튜플 괄호
    studentTuple = ('홍길동', '박찬호', '이용규')
    print('type : {}, tuple : {}'.format(type(studentTuple), studentTuple))
    
    # 튜플 괄호 생략
    studentTuple = '홍길동', '박찬호', '이용규'
    print('type : {}, tuple : {}'.format(type(studentTuple), studentTuple))
    
    # 리스트 괄호
    studentList = ['홍길동', '박찬호', '이용규']
    print('type : {}, tuple : {}'.format(type(studentList), studentList))
  • リストとグラフ変換:リストとグラフをデータ型に変換可能
  • # 리스트
    studentList = ['홍길동', '박찬호', '이용규']
    print('type : {}, tuple : {}'.format(type(studentList), studentList))
    # 아이템의 값을 변경하고 싶지 않다면 튜플로 변환하면 된다.
    castingTuple = tuple(studentList)
    print('type : {}, tuple : {}'.format(type(castingTuple), castingTuple))
    
    # 튜플
    studentTuple = ('홍길동', '박찬호', '강호동')
    print('type : {}, tuple : {}'.format(type(studentTuple), studentTuple))
    # 아이템 값을 변경하고 싶다면 리스트로 변환하면 된다.
    castingList = list(studentTuple)
    print('type : {}, tuple : {}'.format(type(castingList), castingList))

    配置

  • グラフは修正できないので、リストに変換して並べ替え
  • # 정렬
    students = ('홍길동', '박찬호', '이용규', '강호동', '박승철', '김지은')
    print(students)
    # 리스트 변환
    students = list(students)
    # 정렬
    students.sort(reverse=False)
    # 튜플 변환
    students = tuple(students)
    print(students)
  • sorted():リストデータ型をソート関数で返す
  • グラフも並べ替え可能ですが、グラフ変換をやり直す必要があります.
  • 分類(データ、逆=flag)
  • # sorted()
    students = ('홍길동', '박찬호', '이용규', '강호동', '박승철', '김지은')
    print(students)
    newStudents = sorted(students, reverse=False)
    print(newStudents)
    newStudents = tuple(newStudents)
    print(newStudents)

    くりかえし文


    1.For Moon

  • forゲートはグラフのアイテムを参照できます.
  • # for
    # len()
    cars = ('그랜저', '소나타', '말리부', '카니발', '쏘렌토')
    for i in range(len(cars)):
        print(cars[i])
        
    # Iterable
    for car in cars:
        print(car)
        
    # enumerate()
    for idx, car in enumerate(cars):
        print(car)

    2.While文

  • while門はグラフの道具を参照できる.
  • # while
    cars = ('그랜저', '소나타', '말리부', '카니발', '쏘렌토')
    # len() 사용
    n = 0
    while n < len(cars):
        print(cars[n])
        n += 1
    
    # flag 사용
    n = 0
    while True:
        print(cars[n])
        n += 1
    
        if n == len(cars):
            break