| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
| 30 |
- Web
- vscode설치
- phython
- loaddata
- 코딩
- listdir
- SSAFY
- dangerouslySetInnerHTML
- HTML
- 프리워커스
- 파이썬
- LIST
- 위코드
- django
- 오블완
- CSS
- html #css #코딩 #입문 #코딩시작하기 #코딩입문 #파이썬 #자바스크립트 #비전공자 #비전공 #코딩학원
- Python
- 티스토리챌린지
- 파라미터
- comprehension
- Coding
- TIL #todayilearn #math #javascript #js #자바스크립트 #절댓값 #최댓값 #랜덤 #random #floor
- dumpdata
- 역사
- 프로그래밍폰트
- wecode
- CSS #HTML #코드
- 싸피
- VSCode
- Today
- Total
목록comprehension (3)
당신의 친절한 이웃, 코딩맨
import time L = [ 1,2,3] def print_iter(iter): for element in iter: print(element) def lazy_return(num): print("sleep 1s") time.sleep(1) return num print("comprehension_list=") comprehension_list = [lazy_return(i) for i in L] #[1,2,3] print_iter(comprehension_list) print("generator_exp=") generator_exp = (lazy_return(i) for i in L) #[]를 ()로 바꿔줌. print_iter(generator_exp) comprehension_list= slee..
List comprehension은 for 반복문을 활용하여 list를 짧고, 빠르게 만들 수 있는 comprehension이다. [ 표현식 for 원소 in 반복 가능한 객체 ] [ 표현식 for 원소 in 반복 가능한 객체 if문 ] cities = ["Tokyo","Shanghai","Jakarta","Seoul","Guangzhou","Beijing","Karachi","Shenzhen","Delhi"] # 일반적인 for loop new_cities = [] for i in cities: if "S" not in i: new_cities.append(i) print(new_cities) # list comprehension n_l = [x for x in cities if "S" not in x..
표현 방법들 [표현식 for 변수 in 반복(순회) 가능한 객체] ex) numbers = [1, 2, 3, 4, 5] [i * 2 for i in numbers] #[2, 4, 6, 8, 10] [i for i in numbers if i % 2 ==0] #[2, 4] Well.. I really don't use those expressions that much tho; uhm.......maybe for the time will come. for i in range(len(numbers)): numbers[i] = int(numbers[i]) * 2 print(numbers) #[2, 4, 6, 8, 10] However, the list comprehension help your code shor..