Programming68 간결한 python 문법을 쓰자 - lambda python 스러운 코드를 짜자 ex. flatten = lambda l: [item for sublist in l for item in sublist] #을 풀어서 쓰면 def flatten(l:list): a = [] for i in l: for j in i: a.append(j) return a 2022. 5. 9. 간결한 python 문법을 쓰자 - one line condition python 스러운 코드를 짜자 ex. dG ={} current_node = 1 default_p = 0.1 p = dG.get('p_val', default_p) if current_node in dG else default_p #이 한줄코드를 길게 짜면 if current_node in dG: if 'p_val' not in dG[current_node]: p = default_p else: p = dG[current_node]['pval'] else: p = default_p 코드가 짧아지면 좋지만 그건 가독성 & 명료성을 높이는 방향으로 짧아져야 한다. dictionary 의 get(key, default_value) one-line if condition은 가독성도 높이고 간결성도 높인다. 2022. 4. 12. [vscode] Explorer에서 single click로 fileopen 하고 싶지 않을때 (double click 설정) GB단위 csv파일이 있을 경우 눌렀다가 그것 로드하느라 vscode가 죽는 경우가 있다. 해결방법은 ? Preference > setting > "workbench.list.openMode": "doubleClick", 2021. 11. 25. [vscode] 외부 모듈을 debug하고 싶을때 break을 찍어도 내가 짠 코드가 아닌 외부 코드는 break걸리지 않는다. launch.json 설정을 "program": "${file}", "console": "integratedTerminal", "justMyCode": false justMyCode을 False로 해주면 debug 할 수 있다. 2021. 11. 23. 이전 1 2 3 4 5 ··· 17 다음