Tuples 외 2문제

Tuples:

Given an integer, n, and n space-separated integers as input, create a tuple, , of those integers. Then compute and print the result of hash(t).

if __name__ == '__main__':
    n = int(input())
    integer_list = map(int, input().split())
    t = tuple(integer_list)
    print(hash(t))
    # hash 값: 복사된 디지털 증거의 동일성을 입증하기 위해 파일 특성을 축약한 암호같은 수치
    # [출처] [오라클/SQL] ORA_HASH : 해시 값(hash value) 생성 함수|작성자 리제

Lists:

Consider list (list = []). You can perform the following commands:

  1. insert i e: insert integer e at position i
  2. print: Print the list.
  3. remove e: Delete the first occurrence of integer e.
  4. append e: insert integer e t the end of the list.
  5. sort: Sort the list.
  6. pop: pop the last element from the list
  7. reverse: Reverse the list.

Initialize your list and read in the value of n followed by n lines of commands where each command will be of the 7 types listed above. Iterate through each command in order and perform the corresponding operation on your list.

  if __name__ == '__main__':
      N = int(input())
      lst = []
      for i in range(N):
          j = input().split(" ")
          inst = j[0]
          if inst == "insert":
              lst.insert(int(j[1]),int(j[2]))
          if inst == "remove":
              lst.remove(int(j[1]))
          if inst == "print":
              print(lst)
          if inst == "append":
              lst.append(int(j[1]))
          if inst == "sort":
              lst.sort()
          if inst == "pop":
              if(len(lst)!=0):
                  lst.pop()
          if inst == "reverse":
              lst.reverse()

Capitalize:

You are asked to ensure that the first and last names of people begin with a capital letter in their passports. For example, alison heck should be capitalised correctly as Alison Heck.

Given a full name, your task is to capitalize the name appropriately.

def solve(s):
    n = s.split()
    for i in n:
        s = s.replace(i,i.capitalize())
    return s

if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    s = input()

    result = solve(s)

    fptr.write(result + '\n')

    fptr.close()