Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 1
- 1. 튜플의 값들은 수정이 불가능하지만 리스트의 값들은 수정이 가능하다.
- 2. 튜플은 append 함수로 값들을 추가할 수 없지만 리스트는 append 함수로 값들을 추가할 수 있다:
- 3. 튜플은 읽기 전용으로 사용한다
- # 2
- my_profile = {"이름":"송원준", "사는 곳":"용인 수지", "나이":33, "이메일":"balgarac1@naver.com"}
- print(my_profile)
- # 3
- my_profile = {"이름":"송원준", "사는 곳":"용인 수지", "나이":33, "이메일":"balgarac1@naver.com"}
- brother_profile = {"이름":"송원재", "사는 곳":"용인 수지", "나이":32}
- family = []
- my_profile_str = ""
- for k, v in my_profile.items():
- my_profile_str += k
- my_profile_str += ":"
- my_profile_str += str(v) + " "
- family.append(my_profile_str)
- brother_profile_str = ""
- for k, v in brother_profile.items():
- brother_profile_str += k
- brother_profile_str += ":"
- brother_profile_str += str(v) + " "
- family.append(brother_profile_str)
- print(family)
- # 4
- my_profile = {"이름":"송원준", "사는 곳":"용인 수지", "나이":33, "이메일":"balgarac1@naver.com"}
- brother_profile = {"이름":"송원재", "사는 곳":"용인 수지", "나이":32}
- family = []
- my_profile_str = ""
- for k, v in my_profile.items():
- my_profile_str += k
- my_profile_str += ":"
- my_profile_str += str(v) + " "
- family.append(my_profile_str)
- brother_profile_str = ""
- for k, v in brother_profile.items():
- brother_profile_str += k
- brother_profile_str += ":"
- brother_profile_str += str(v) + " "
- family.append(brother_profile_str)
- for k in range(0, len(family)):
- family[k] = family[k].strip().replace(" ", ",").replace(":", ",")
- print(family)
- # 5
- print(PEP)
- alpha = {}
- for letter in range(ord('a'), ord('z') + 1):
- if PEP.lower().count(chr(letter)):
- alpha[chr(letter)] = PEP.lower().count(chr(letter))
- print(alpha)
- # 6
- [1,2,3,4,5,6] => print([i for i in range(1,7)])
- [6,5,4,3,2,1] => print([i for i in reversed(range(1,7))])
- [[1,2,3],[1,2,3],[1,2,3]] => print([[i for i in range(1,4)] for i in range(1, 4)])
- [[1,2,3],[4,5,6],[7,8,9]] => print([[x for x in range(1, 4)],[x for x in range(4, 7)],[x for x in range(7, 10)]])
Add Comment
Please, Sign In to add comment