본문 바로가기

IT World/Python16

Python Training Day 13. Lambda functions Chapter 15. Lambda functions Instead of defining the function somewhere and calling it, we can use python's lambda functions, which are inline functions defined at the same place we use it. They don't need to have a name, so they also called anonymous functions. We define a lambda function using the keyword lambda. your_function_name = lambda inputs : output Exercise l = [2,4,7,3,14,19] for i in.. 2022. 12. 26.
Python Training Day 12. List Comprehensions Chapter 14. List Comprehensions List Comprehensions is a very powerful tool, which creates a new list based on another list, in a single, readable line. for loops vs. list comprehension # for loop word_lengths = [] for word in words: if word != "the": word_lengths.append(len(word)) # list comprehension word_lengths = [len(word) for word in words if word != "the"] time comparison 2030개의 단어를 가진 St.. 2022. 12. 25.
Python Training Day 10 & 11. Pandas Basics, Generators Chapter 13. Pandas Basics Pandas DataFrames It is built on the Numpy package and its key data structure is called the DataFrame. There are several ways to create a DataFrame. One way is to use a dictionary. Another way to create a DataFrame is by importing a csv file using Pandas. dict = {"country": ["Brazil", "Russia", "India", "China", "South Africa"], "capital": ["Brasilia", "Moscow", "New De.. 2022. 12. 23.
Python Training Day 9. Numpy Arrays Chapter 12. Numpy Arrays (learnpython) Numpy arrays are great alternatives to Python Lists. Fast, easy to work with, and give users the opportunity to perform calculations across entire arrays. # Create 2 new lists height and weight height = [1.87, 1.87, 1.82, 1.91, 1.90, 1.85] weight = [81.65, 97.52, 95.25, 92.98, 86.18, 88.45] import numpy as np # Create 2 numpy arrays from height and weight n.. 2022. 12. 20.
Python Training Day 8. Modules and Packages Chapter 11. Modules and Packages (learnpython.org) Exercise 오늘은 다른 더 중요한 일이 있어서 Exercise 결과만 올려두고, 텍스트 정리는 내일 하려 한다. 2022. 12. 19.
Python Training Day 7. Dictionaries Chapter 10. Dictionaries (learnpython.org) 1. How to define a dictionary phonebook = {} phonebook["John"] = 938477566 phonebook["Jack"] = 938377264 phonebook["Jill"] = 947662781 phonebook = { "John" : 938477566, "Jack" : 938377264, "Jill" : 947662781 } 2. Iterating over dictionaries phonebook = {"John" : 938477566,"Jack" : 938377264,"Jill" : 947662781} for name, number in phonebook.items(): prin.. 2022. 12. 18.
Python Training Day 6. Classes and Objects Chapter 9. Classes and Objects (learnpython.org) Objects are an encapsulation of variables and functions into a single entity. Objects get their variables and functions from classes. class MyClass: variable = "blah" def function(self): print("This is a message inside the class.") myobjectx = MyClass() # -------Accessing Object Variables------- myobjectx.variable print(myobjectx.variable) class M.. 2022. 12. 17.
Python Training Day5. Functions Chapter 8. Functions Define functions 1. Functions in python are defined using the block keyword "def", followed with the function's name as the block's name. 2. Functions may also receive arguments (variables passed from the caller to the function). 3. Functions may return a value to the caller, using the keyword- 'return' . Call functions Simply write the function's name followed by (), placin.. 2022. 12. 16.
Python Training Day4. Loops 오늘은 프로그래밍의 기본이자 꽃 Loop 문제를 풀었다. 문제가 쉬워서 출근 길, 회사에서 화장실 가는 길 걸어다니며 다 했다. 퇴근 길에 포스팅까지 마무리! Chapter 7. Loops 1. The "for" loop 2. "while" loops 3. "break" and "continue" statements 4. Can we use "else" clause for loops? Exercise List 안의 숫자 237까지만 출력되게 하고, 그 뒤 숫자들은 출력하지 않는 조건의 문제였다. for, while, break, continue를 쓸 때 신경써야 할 것은 print를 어느 위치에서 찍느냐이다. 2022. 12. 15.
Python Training Day3. Conditions 다행히 오늘 주제는 내용이 많지 않아서 금방 끝낼 수 있었다. True, False에 대한 내용이다. (그런데, 문제 푸는 것보다 포스팅하는 게 더 오래 걸리는 건 어떻게 해결해야 할까 생각 좀 해 봐야겠다) Chapter 6. Conditions Python uses boolean logic to evaluate conditions. The boolean values True and False are returned when an expression is compared or evaluated. 1. The "and" and "or" boolean operators allow building complex boolean expressions. 2. The "in" operator could be use.. 2022. 12. 14.