개발/Python
-
[Python] - Generator개발/Python 2022. 7. 28. 16:38
Generator Generator functions allow you to declare a function that behaves like an iterator, it can be used in a for loop. Generator call like iterator whenever you need 1. yield if use normal function 'return' get value , but Generator use 'yield' yield can be used to control the iteration behaviour of a loop instead of building an array containing all the values and returning them all at once,..
-
[Python] - Call by Object reference & Call by sharing개발/Python 2022. 7. 28. 15:08
1. Call by value call by value used to C programming call the function , parameter copied value and pass value arguement so, do not changed origin data within function 2. Call by reference (pointer) call by reference used to Java programming parameter copied reference = pointer (value address) so, function can access origin data by address 3. Call by object reference( Call by sharing ) Python's ..
-
[Python] - Counter개발/Python 2022. 7. 27. 20:24
Counter A Counter is a dict subclass for counting hashable objects. collection where elements are stored as dictionary keys and their counts are stored as dictionary values. Syntax Counter([iterable-or-mapping]) from collections import Counter c = Counter('gallahad') > Counter({'a': 3, 'l': 2, 'g': 1, 'h': 1, 'd': 1}) c = Counter({'red': 4, 'blue': 2}) > Counter({'red': 4, 'blue': 2}) c = Counte..
-
[Python] - Permutation & Combination개발/Python 2022. 7. 27. 19:50
Permutation process of changing the linear order of an ordered set support itertools Permutations differ from combinations , which are selections of some members of a set regardless of order set {1, 2, 3} -> (1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1) Syntax permutations(iterable, r=None) from itertools import permutations list( permutations('ABC', 2) ) > [('A', 'B'), ('A', ..
-
[Python] - N진수 표현 및 Ascii개발/Python 2022. 7. 27. 18:07
Python 진법 변환 1. N Base -> 10 Base value is A number or a string that can be converted into an integer number base is A number representing the number format. Default value − 10 Syntax - int(value, base) # N base to 10 base print(int('101',2)) > 5 print(int('202',3)) > 20 print(int('ADF',16)) > 2783 2. 10 Base -> 2 / 8 / 16 Base bin(), oct(), hex() function support # 2base print(bin(11)[2:]) > 10..
-
[Python] - Regular expression개발/Python 2022. 7. 27. 17:29
Regular Expression 1.meta characters . ^ $ * + ? { } [ ] \ | ( ) 1.1) character class [] regular expression between [ and ] is matching characters '-' operator mean From - To ( [0-5] -> [012345] ) '^' operator mean Not '.' operator mean all characters except \n '*' operator mean repeat characters 0~N ( N maybe 2000000000 because memory limit ) '+' operator mean repeat characters 1~N {m,n} operat..
-
[Python] - Sort / Reverse개발/Python 2022. 7. 27. 15:26
1. Sort Only List(In-place) Reverse = [::-1] a = [1,5,2,4] a.sort() > [1,2,4,5] # a.sort() -> a[::-1] a.sort(reverse=True) > [5,4,2,1] 2. Sorted Use Iterable Object A simple ascending sort and returns a new sorted list key parameter call function for list element #iterable dict temp = {1: 'D', 2: 'B', 3: 'B', 4: 'E', 5: 'A'} sorted(temp) > [1, 2, 3, 4, 5] sorted(temp.items()) > [(1, 'D'), (2, 'B..
-
[Python] - Iterators개발/Python 2022. 7. 27. 15:01
Iterators An iterator is an object that contains a countable number of values. An iterator is an object that can be iterated upon, meaning that you can traverse through all the values. Technically, in Python, an iterator is an object which implements the iterator protocol, which consist of the methods __iter__() and __next__(). iterable Lists, tuples, dictionaries, and sets are all iterable obje..