Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- SQL
- docker
- pagination
- imagemagick
- ec2
- view
- ubuntu
- cron
- centOS7
- codeigniter4
- Wordpress
- php
- linux
- dockerfile
- laravel
- MySQL
- AWS
- Ruby On Rails
- controller
- Git
- NGINX
- docker-compose
- 서브쿼리
- Selenium
- props
- vue
- react
- javascript
- Python
- ruby
Archives
- Today
- Total
내가 한 노력들
[ python ] list 에서 value 값으로 다중 index 찾기 본문
result = [1,2,3,4,5,3]
result 라는 list 에서 원소값이 3인 index번호를 알고 싶을 때는??!
print(test_list.index(3))
index() 를 사용하게되면 list안에 중복된 value가 있을 때에는 index 번호가 빠른 것만 결가값이 나오게 된다.
결과값
2
rest_list = list(filter(lambda x: test_list[x] == 3, range(len(test_list))))
print(rest_list)
list(filter()) 를 이용해서 list안에 중복되는 value값이 있어도 다중의 index 번호를 list의 값을 준다.
결과값
[2, 5]
여기서 fillter()는
filter 함수는 built-in 함수로 list 나 dictionary 같은 iterable 한 데이터를 특정 조건에 일치하는 값만 추출해 낼때 사용하는 함수이다.
def func(x):
if x > 0:
return x
else:
return None
list(filter(func, range(-5,10)))
>>> [1, 2, 3, 4, 5, 6, 7, 8, 9]
참고URL
출처: https://bluese05.tistory.com/66 [ㅍㅍㅋㄷ]
'IT 공부 > python' 카테고리의 다른 글
[ python ] random 모듈 사용해서 난수 만들기 (0) | 2020.11.20 |
---|---|
[ python ] zfill() 문자열 앞에 0 자리수를 채워주고 싶을 때 (0) | 2020.11.20 |
2020-11-15 python 여러가지 module (0) | 2020.11.15 |
2020-11-11 python *args 와 **kwargs (0) | 2020.11.11 |
[ Python ] dictionary values값으로 key값 찾기 (0) | 2020.11.08 |