728x90
반응형

프로그래밍 지식/Python 24

[Python] 포맷팅, 문자열 복습

https://www.hackerrank.com/challenges/finding-the-percentage/problem Finding the percentage | HackerRank Store a list of students and marks in a dictionary, and find the average marks obtained by a student. www.hackerrank.com 이 문제를 기반으로 설명한다. 사실 다른 답이 더 간단한데 난 저렇게 생각나서 그냥 저렇게 바로 해버렸다. 뭐 최적화랑 문제의 답을 내는 것은 다르니까 ㅎㅎ refacotring 한 다른 사람의 답을 보자면 그렇다는데 공부해보자 ㅎㅎ

[Python] konlpy 사용시 오류, JVMNotFoundException: No JVM shared library file (jvm.dll) found. Try setting up the JAVA_HOME environment variable properly.

JVMNotFoundException: No JVM shared library file (jvm.dll) found. Try setting up the JAVA_HOME environment variable properly. 요딴 오류가 생기는데 구글링해서 찾았다. 그냥 JVM을 못찾는단다. 그래서 직접 가서 수정해줘야 한다. anaconda로 들가서 \anaconda3\Lib\site-packages\jpype _jvmfinder.py 파일을 수정해주자. 여기 경로에 있을 거다. 직접 jdk위치를 설정해주자. 바꿔주면 된단다. 해보자 참고링크 https://www.phpschool.com/gnuboard4/bbs/board.php?bo_table=talkbox2&wr_id=1147061

[Python] 반복 any(), all()

https://www.hackerrank.com/challenges/string-validators/problem String Validators | HackerRank Identify the presence of alphanumeric characters, alphabetical characters, digits, lowercase and uppercase characters in a string. www.hackerrank.com 사실 이렇게 안해도 됐는데...ㅋㅋㅋㅋㅋ 더 간단한 답은 밑에 있다. 나와 같은 원리지만 내가 any()를 쓰지 않아서 벌어진 일이었다. any() 괄호안의 값이 하나라도 참이면 True를 출력 all() 괄호안의 값이 하나라도 거짓이면 False를 출력 str = raw_..

[Python] string, 문자열 인덱스 활용하기

https://www.hackerrank.com/challenges/find-a-string/problem?h_r=next-challenge&h_v=zen&h_r=next-challenge&h_v=zen&h_r=next-challenge&h_v=zen&h_r=next-challenge&h_v=zen Find a string | HackerRank Find the number of occurrences of a substring in a string. www.hackerrank.com 이 문제를 기반으로 설명한다. 주석을 영어로 써놨는데 맞는지 모르겠다 ㅋㅋㅋㅋ 뭐 추가설명은 없다.

[Python] 문자열, 리스트 변환

https://www.hackerrank.com/challenges/python-mutations/problem?h_r=next-challenge&h_v=zen&h_r=next-challenge&h_v=zen&h_r=next-challenge&h_v=zen Mutations | HackerRank Understand immutable vs mutable by making changes to a given string. www.hackerrank.com 이 문제를 기반으로 설명한다 mutable, immutable 둘 구분할 수 있어야 한다. 우선 str은 immutable 이고 list 는 mutable이다. 즉 str을 수정하고 싶다면 list로 바꾸어서 수정해야 한다. 위는 그 과정이다.

[Python] upper(), lower() 활용하기

https://www.hackerrank.com/challenges/python-string-split-and-join/problem?h_r=next-challenge&h_v=zen String Split and Join | HackerRank Use Python's split and join methods on the input string. www.hackerrank.com 이 문제를 기반으로 설명하고 문자열을 인덱싱을 통해서 하나 하나 전수조사를 할 수 있다. 뭐 S를 직접 바꾸어도 좋지만 원래 있던 데이터를 바꾸는 것은 그리 좋지 않은 방법인데다가. 굳이 복사해서 다시 쓸필요도 없기에 새로운 문자열을 만들어서 활용하는 것이 좋다. 그래서 a =""라는 빈 문자열을 만들어서 +연산을 수행해서 붙여썼..

[Python] 리스트 기초, 문자열을 명령어로 수행 eval(), join()

https://www.hackerrank.com/challenges/python-lists/problem Lists | HackerRank Perform different list operations. www.hackerrank.com 이 문제를 기반으로 설명한다. 리스트에 관한 연산은 다 나와있다. 뭐 영어로 내가 주석을 달아봤지만,, 어디까지나 아마추어의...주석이고 아무튼 문제를 보면 input으로 받을 것이 3가지나 된다. 그래서 split()으로 공백을 기준으로 쪼개서 받았고 그 3가지를 분류해서 활용해야하기에 빈 리스트를 만들어서 할당했다. 그리고 다시 그것들을 명령어로 바꾸기 위해 eval()같은 것들을 사용했다. ",".join(args) 의 뜻은 args 사이에 , 를 집어넣겠다는 뜻이다.

[Python] List comprehension, 리스트 컴프리헨션

https://www.hackerrank.com/challenges/nested-list/problem Nested Lists | HackerRank In a classroom of N students, find the student with the second lowest grade. www.hackerrank.com 이 문제를 기반으로 설명한다. 여기서 쓰인 것을 List comprehension이라고 하는데 책에는 잘 안나와서.. 어려울 수 있다. for문을 쓸 때 앞에 아무것도 안 붙이니까!! 그래서 LIne 6을 보면 어떤가 보니 for name, marks in marksheets // 즉 marksheets에 들어있는 것들을 name, marks 라는 변수로 차례대로 불러들일 거고 그 중 m..

[Python] 리스트 응용하기

https://www.hackerrank.com/challenges/find-second-maximum-number-in-a-list/problem Find the Runner-Up Score! | HackerRank For a given list of numbers, find the second largest number. www.hackerrank.com 이 문제를 기반으로 설명했다. 사실 pop으로 할 수 있을 줄 알았다. 그렇지만 무작위로 리스트가 만들어졌기 때문에 2번째로 큰 값을 알기 위해서 정렬을 해도 괜찮았지만 다른 방법인 remove를 찾기로 했다. 최댓값이 바뀔 때까지 최댓값을 삭제하는 것이다. 다른 방법으로는 중복을 방지하려고 set으로 바꿨다 다시 list로 바꿀 수 있다. 뭐가 더..

728x90
반응형