Start studying: Saturday, December 7th Books used: Miyuki Oshige "Details! Python3 Introductory Note ”(Sotec, 2017)
Resume from [Sort elements in the list (Ch.6 / p.170)](6th day), Finished until [Retrieving values from dictionary (Ch.9 / p.229)](7th day)
-Write a for-in syntax in [] and create a new list from iterable objects. (Iterable: An object that can retrieve the elements contained in the value one by one.) -You can handle two lists at the same time with zip (). The length is the same as the shorter one. ・ A conditional expression can be added with an if statement. (Expression for variable in iterable if conditional expression) Extract only those that meet the conditions in the list. (Natural numbers only, etc.) -It is also possible to insert multiple for-in statements. (Extracting the nesting list)
-Implemented with the in operator. BIG3 = ["Bench Press", "Squat", "Deadlift"] "Bench press" in BIG3 → True, "Arm curl" in BIG3 → False Partial search is not possible as it only searches for matches "Bench" in BIG3 → False. (If implemented, for-if statement) ・ Index () → Returns the index number of the found location. ・ Count () → Returns the number found.
-Treat multiple values as one. Separate with commas. Or the built-in function tuple () -Lists are mutable (variables that can be changed), tuples are immutable (variables that cannot be changed) The list is [] and the tuple is (). The contents cannot be changed, but can be overwritten or concatenated Mutual conversion is possible with list () ⇆ tuple ()
-If the numerical value to be embedded in the character string is used as the argument of format (), it will be entered in the replacement field {} in order. This code can also be written with f "{} (past review, p.90). -Create a set by separating the values you want to group with commas and enclosing them in {}. ** Unlike the list, duplicate elements cannot be included ** (Even if they are included, they can be combined into one) -Like a list, the number of elements is counted by len (). -There is also a combination technique of deleting duplicate values with set (), listing with list (), and sorting with sort (). -Add an element with add (), delete an element with remove () or discard (), and empty it with clear (). -Although you can retrieve elements with pop (), you cannot specify the index number because there is no concept of alignment in the set. -Frozenset () can be used to create a set that cannot be added or changed.
The notation method is almost the same as the list comprehension notation. [] Becomes {}.
-Since a set treats multiple values as a ** set **, it cannot be calculated with operators like a list. Therefore, if you want to find the union, you need to use the | operator or union (). Of course, if there are duplicate values, it will be one. In terms of number A (is it?), The image is A∪B (recognized as) -The product set is the & operator, intersection (), or the intersection. A∩B ・ The difference set is the operator or difference (), (A∪B) -B (may be wrong) ・ The target difference is the ^ operator or symmetric_difference (), (A∪B)-(A∩B) (may be wrong) -Update () updates the set with the union with the element given as an argument, what is the difference from add? I know it's different, but I'm not sure. Can you write them all together? Hold for the time being
-Same as a list, a data format that handles multiple values together By setting the "key", the value of the specified element is retrieved. ・ Notated as {key: value}. Keys can only be set to immutable values (that is, tuples can be set) ・ Dictionary with dict () -The value can be changed / added with the dictionary [key] = value. setdefault () is left as it is if there is a key, otherwise added
Recommended Posts