Created
March 25, 2018 01:42
-
-
Save jennyonjourney/24c969e82a38ced5a5a7e5e77cb8a155 to your computer and use it in GitHub Desktop.
Python - Set & Tuple
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s1 = set([1,2,3,4,5,6]) | |
s2 = set([4,5,6,7,8,9]) | |
uu = s1|s2 | |
ii = s1&s2 | |
mm = s1-s2 | |
uu=s1.union(s2) | |
ii=s1.intersection(s2) | |
mm=s1.difference(s2) | |
print(uu) | |
print(ii) | |
print(mm) | |
t1 = set(['박제상','박정권','최정','김광헌','엄정욱','박희수','이호준']) | |
t2 = set(['이호준', '엄정욱','박재홍', '이신협', '장동건']) | |
fa = set(['이병규', '이승엽','박정권','장동건','박용택','홍성훈']) | |
newt1 = t1-t2-fa | |
newt2 = t2-fa | |
newfa = fa-t1-t2 | |
print(newt1) | |
print(newt2) | |
print(newfa) | |
print('----------Tuple--------------') | |
arr1 = [11,22,33,44] | |
arr2 = (1111,2222,3333,4444) | |
arr3 = 11,22,33,44 | |
print(arr1, type(arr1)) | |
print(arr2, type(arr2)) | |
print(arr3, type(arr3)) | |
print(arr2[1]) | |
print(arr2[1:-1]) | |
print(len(arr2)) | |
print(arr2.count(22)) | |
print('---------------') | |
arr4 = arr2+arr3 | |
print(arr4) | |
arr5 = arr2*3 | |
arr6 = arr2[1:3] | |
print(arr5) | |
print(arr6) | |
print('---------------') | |
#리스트로 바꾸고 싶은데유 | |
arr7 = list(arr2) | |
print(arr7) | |
print(arr2) | |
arr2 = list(arr2) | |
print(arr2) | |
print('---------------') | |
#튜플로 바꾸고 싶은데여 | |
arr8 = tuple(arr1) | |
print(arr8) | |
print(arr1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment