- 74
- 53 346
Alexander Hess - Pythonista
Germany
เข้าร่วมเมื่อ 2 ม.ค. 2012
I teach Python.
To anybody who wants to listen.
Mostly, that means students at my alma mater WHU - Otto Beisheim School of Management in Germany.
I also run in-house workshops for companies and research institutions. Interested? Get in touch and hire me.
My background is in data science with supply chain applications.
To anybody who wants to listen.
Mostly, that means students at my alma mater WHU - Otto Beisheim School of Management in Germany.
I also run in-house workshops for companies and research institutions. Interested? Get in touch and hire me.
My background is in data science with supply chain applications.
Popular examples of iterators
In this video, I show how we were using iterators already long before we formally introduced them in this course. For example, the range() built-in creates objects that behave like iterators (although they are actually not iterators). Other examples of iterators are the objects returned by the reversed(), zip(), and enumerate() built-ins. The commonality among them is that all of them model "rules in memory" that know how to generate a "next" element without generating it yet.
PYTHON BOOK
The lecture is based on the free book "Introduction to Python & Programming".
Get it on GitHub: github.com/webartifex/intro-to-python
SUBSCRIBE
If you like the way I teach and talk about programming and data science, subscribe to this channel.
The videos focus on coding courses and tutorials aimed at managers and students of business administration, enabling them to make better decisions with analyses done in code.
INSTRUCTOR
Alexander Hess, PhD Student
WHU - Otto Beisheim School of Management, Vallendar, Germany
CONTACT
GitHub: github.com/webartifex
LinkedIn: linkedin.com/in/webartifex
XING: xing.to/webartifex
Facebook: webartifex
Instagram: webartifex
Website: www.webartifex.biz
TH-cam: th-cam.com/users/webartifex
wa-vid-075
PYTHON BOOK
The lecture is based on the free book "Introduction to Python & Programming".
Get it on GitHub: github.com/webartifex/intro-to-python
SUBSCRIBE
If you like the way I teach and talk about programming and data science, subscribe to this channel.
The videos focus on coding courses and tutorials aimed at managers and students of business administration, enabling them to make better decisions with analyses done in code.
INSTRUCTOR
Alexander Hess, PhD Student
WHU - Otto Beisheim School of Management, Vallendar, Germany
CONTACT
GitHub: github.com/webartifex
LinkedIn: linkedin.com/in/webartifex
XING: xing.to/webartifex
Facebook: webartifex
Instagram: webartifex
Website: www.webartifex.biz
TH-cam: th-cam.com/users/webartifex
wa-vid-075
มุมมอง: 404
วีดีโอ
Comparing iterators with iterables
มุมมอง 3073 ปีที่แล้ว
In this video, I compare iterators (= "rules in memory") with iterables (= all objects over which we can loop). Iterators are always also iterables but the converse is not true. We see how the built-in iter() function creates an iterator out of an iterable argument. The iterator is then the "manager" of the iteration logic. PYTHON BOOK The lecture is based on the free book "Introduction to Pyth...
Creating "rules in memory" with generator expressions
มุมมอง 2143 ปีที่แล้ว
In this video, I introduce the generator data type. In spirit, it is related to the map and filter types created with the map() and filter() built-ins. We see how we should think of generators as flexible "rules in memory" that allow processing big amounts of (sequential) data on a one-by-one basis without needing a significant amount of memory. PYTHON BOOK The lecture is based on the free book...
Using map() and filter() with lambda expressions
มุมมอง 2103 ปีที่แล้ว
In this video, I review the example of the previous two videos, "A first look at the map-filter-reduce paradigm" and "Modeling 'rules in memory' with map() and filter()", and show how we can use the map() and filter() built-ins without having to define a functions. That is achieved with lambda expressions that upon evaluation create new function objects that have no name. Other than that, they ...
Modeling "rules in memory" with map() and filter()
มุมมอง 2033 ปีที่แล้ว
In this video, I review the example of the previous video "A first look at the map-filter-reduce paradigm", and show how we can use the map() and filter() built-ins to solve the same problem without using the memory in a significant way. map() and filter() produce objects of types map and filter that can be though of as "rules in memory" that know to generate a "next" element without generating...
A first look at the map-filter-reduce paradigm
มุมมอง 2233 ปีที่แล้ว
In this video, I introduce the map-filter-reduce paradigm. Conceptually speaking, it is simply a classification scheme for the individual processing steps involved in some "bigger" computational problem. In the video, we use memory inefficient temporary lists to solve an easy task. In the next video, we revisit the example and show how built-in data types can help us get to a memory efficient s...
Tuples as records of data
มุมมอง 2453 ปีที่แล้ว
In this video, I talk about how we can view tuples as records of data. A record is a collection of fields and we use tuples to glue together otherwise unrelated objects. We see how namedtuples can then be used to extend this idea and add semantics into a program. That is a first step towards object orientation. PYTHON BOOK The lecture is based on the free book "Introduction to Python & Programm...
Packing & unpacking
มุมมอง 2493 ปีที่แล้ว
In this video, I talk about a nice "application" of tuples (and iterables in general), namely packing and unpacking. These concepts enable us to easily flip the values of two variables or design a function such that it can take as many arguments as we want. PYTHON BOOK The lecture is based on the free book "Introduction to Python & Programming". Get it on GitHub: github.com/webartifex/intro-to-...
Tuples are like immutable lists
มุมมอง 2243 ปีที่แล้ว
In this video, I talk about the tuple data type. In short, tuples are like immutable lists. All "read-only" methods and operations of lists are also available for tuples. A good practice is to use tuples instead of lists as the default choice when working with sequential data and only revert to lists if mutation is needed. PYTHON BOOK The lecture is based on the free book "Introduction to Pytho...
Lists as arguments: Pure vs. modifier functions
มุมมอง 4743 ปีที่แล้ว
In this video, I explain the consequences of using list objects as arguments in function calls. In particular, we must understand that lists are mutable, and whenever we change a list that is passed in as an argument the "outside world" (= caller of the function) also sees these changes! This may be done on purpose but often times it is better to first make a copy of a list within the function'...
Popular list operations to know
มุมมอง 1733 ปีที่แล้ว
In this video, I explain how list objects behave when used with arithmetic or relational operators. In particular, we review the concept of concatenation that we already know from the discussion about string operations. Also, list comparison works according to the same logic as string comparison. Last, we briefly talk introduce the idea of unpacking that allows us to access the data in a list i...
Popular list methods to know
มุมมอง 2533 ปีที่แล้ว
In this video, I review popular list methods like the .append(), .extend(), .insert(), .pop(), and .remove() methods. Also, we compare the .sort() method with the built-in function sorted(). Most list methods have no return value indicating that the changes happen "in place", which is mostly the desired behavior for mutable data types. PYTHON BOOK The lecture is based on the free book "Introduc...
Shallow vs. deep copies
มุมมอง 2093 ปีที่แล้ว
In this video, I explain the difference between shallow and deep copies with the example of a nested list object. Shallow copies simply copy the references inside a container objects whereas deep copies also follow the references recursively and duplicate an entire data structure in memory. Shallow copies take a lot less memory but will lead to semantic errors in a program when the data inside ...
Lists are mutable sequences
มุมมอง 2553 ปีที่แล้ว
In this video, I talk about the basics of the list data type. We see how lists contain merely references to other objects and review the four properties every sequence has and conclude that lists are simply mutable sequences. PYTHON BOOK The lecture is based on the free book "Introduction to Python & Programming". Get it on GitHub: github.com/webartifex/intro-to-python SUBSCRIBE If you like the...
Sequences are sized and ordered containers that we can loop over
มุมมอง 2223 ปีที่แล้ว
In this video, I explain what the list and str data types have in common. In particular, they share four properties: 1) container, 2) sized, 3) iterable, and 4) reversible. All data types with these properties are also referred to as sequences. PYTHON BOOK The lecture is based on the free book "Introduction to Python & Programming". Get it on GitHub: github.com/webartifex/intro-to-python SUBSCR...
String interpolation with f-strings and the format() method
มุมมอง 2503 ปีที่แล้ว
String interpolation with f-strings and the format() method
Classifying numbers with the numeric tower
มุมมอง 2383 ปีที่แล้ว
Classifying numbers with the numeric tower
Floating point numbers are inherently imprecise
มุมมอง 2763 ปีที่แล้ว
Floating point numbers are inherently imprecise
How (integer) numbers are represented in memory
มุมมอง 5203 ปีที่แล้ว
How (integer) numbers are represented in memory
Abstract vs. Concrete Data Types in Python
มุมมอง 8263 ปีที่แล้ว
Abstract vs. Concrete Data Types in Python
Using indefinite loops to write interactive games
มุมมอง 2843 ปีที่แล้ว
Using indefinite loops to write interactive games
Collatz' Conjecture: How many iterations do we need?
มุมมอง 6823 ปีที่แล้ว
Collatz' Conjecture: How many iterations do we need?
Validating input with the type checking & type casting strategies
มุมมอง 3153 ปีที่แล้ว
Validating input with the type checking & type casting strategies
Finding Fibonacci numbers in two ways: Recursion & Looping
มุมมอง 4273 ปีที่แล้ว
Finding Fibonacci numbers in two ways: Recursion & Looping
Finding the factorial of a number in two ways: Recursion & Looping
มุมมอง 4123 ปีที่แล้ว
Finding the factorial of a number in two ways: Recursion & Looping
Executing code repeatedly with a while loop
มุมมอง 4073 ปีที่แล้ว
Executing code repeatedly with a while loop
Executing code repeatedly with a recursion
มุมมอง 5593 ปีที่แล้ว
Executing code repeatedly with a recursion
well explained!!
Thanks!
How can titels be numbered automatically?
That happens automatically withing JupyterLab with an extension.
Which extension, like MS Word?
Thank you very much. This video helped me shape and format the course project.
Glad it helped!
Thank you for very informative video!
My pleasure!
great video!
Thanks :)
Thank you for this explanation! I found it especially useful when you used python tutor as I realized an iterator works like the "manager" of the iteration process.
That is actually a wonderful observation you made. I like the term "manager". It's not formal but explains the idea in a beginner friendly way. Thanks!
Is there any particular reason why we used the random.random() function instead of random.choice()?
The `random.random()` function allows us to fine-tune the probabilities in a way more convenient way than the `random.choice()` function. Think of the expression `random.random() < p_heads` which is `True` exactly "p_heads %" of the time.
The video really helped me to better understand the rules & mindset of Python and write first, small codes by myself :). Maybe you could show in the future, at the beginning of the video a kind of content overview, so we better understand why the individual chapters come in the order they were discussed. It was a bit hard for me to find the thread at the beginning, but the longer I watched the video, the easier it was to follow. Kind regards from Fabian, Bsc 2024
Hi. I think you unfortunately watched the old playlist on the Python contents in my book. Here is the newer videos with shorter videos and video titles on a per topic basis that make a lot more sense: th-cam.com/play/PL-2JV1G3J10kRUPgP7EwLhyeN5lOZW2kH.html
Hi Alex, therefore if I use the attribute b.is_float() on b I would receive the same error?
Hi Richard. There is no such method on any data types in Python, at least not the built-in ones. You are confusing them the ".is_float()" method a) with the ".is_integer()" method on the `float` object or b) you simply want to know if an object is a `float` which you can find out with the type(obj) function
why I cannot delete one column with double D in Mac?
Because the pro's all use Linux and not Mac ;)
Just kidding. Double D should work in Mac as well. You probably forgot to "leave" the cell with the "Escape" key first. Let me know if that works.
I have solved this following your instructions. Thanks.@@webartifex
Life saver man. Was searching for this from so long
Thanks :)
Bro u are goated 👑👑👑
Really?
Just to be sure: attributes like .sort() can not be applied to int, right?
Nope. ".sort()" belongs to other data types, e.g., the list data type
i really appreaciate the time stemps here, would love to see them more in the other videos.
Noted!
Very nice video mate, a lot of great questions about how to develop and justify some choices in data science.
Glad you liked it!
make a detailed video about environment and how to add them to ide or code editors, there are no proper video about these on yt
i will do that for my next recording of my lectures :)
very good
Thanks
Thank you very much for the explanation! How exactly are tuples and lists different other than their mutability? I don't think I quite got that.
That part you mention is the MAIN difference. In addition, because of that difference, tuples do not have methods that mutate a list.
Many thanks for the videos! They were very helpful in understanding the content of the lectures in more detail.
You are welcome!
Thanks, well explained!
You're welcome!
By generating the list in lists, does it create a completely new list? If I change something in the first list will it automatically update?
Lists within lists may lead to "weird" situation from a beginner's point of view, especially if the outer list is copied somehow (or sliced). That happens because then we have more than one outer list referring to the same inner lists, which are not copied.
Thank you for the great video! Is it possible to receive a run-time error? Especially by making more complex loops or recursions?
Yes, practically, runtime errors can occurs. Python by default can only store up to 3000 concurrent function calls in memory. That number can be changed but will always be some finite limit. Beyond that, we will see an error message
In your corresponding book on Github you have a review question that asks whether "a substring is a string that subsumes another string". I am aware of the concept of substrings. It's a short string within a larger string object (e.g. we could obtain it via list comprehension). Somehow I don't fully understand the meaning/ logic of the word "subsumes" in this context. Is the question therefore true or false? Many thanks in advance!
The word "subsumes" here means "contains" => Therefore, the opposite is true: A substring IS subsumED by another string
After analyzing the videos and building Your demonstrated code, I am understanding why PEP 8 is used by so many Python users. Thanks a lot!
And PEP8 is only considered the bare minimum style guide. In practice, people use even more styling rules
By unpacking the list, do further changes influence the new list?
What do you mean with further changes?
Is it possible to set a "dynamic" f-string including an input to get a "dynamic" return?
From how I interpret your understanding of "dynamic", that is exactly what f-strings are for: They are a template containing a "dynamic" part
Is it possible to take a view on the whole library of the imported "math"?
Kind of: "dir(math)" shows all the functions and constants while "help(math)" shows even more descriptions
For solving this kind of questions where Recursion and Looping is giving the same result, which way is the more efficient one? Thanks! Paweł L.
In Python, if you can find a looping solution, it will be more memory efficient because Python then does not need to manage all the ongoing function calls
Hey! I was trying to handle this example. Unfortunately the "except" is showing an invalid syntax. Do You have an idea why this is not working? Thank You! Paweł L.
Which part?
Could You please explain which advantage is made by making the lambda function in comparison to the typical function. Thank You! Pawel L.
They are useful in places where one needs to provide a function however there is no need to call that more than once. (Normal) functions with names are mainly there to be re-used!
In addition to your videos I also had a look into your corresponding book on Github. In Chapter 2 under the review questions there is a true/false question asking "A mere function call is just an expression". In Chapter 7 (Sequential Data) you talk about so called modifier and pure functions. Modifier functions change the input variables (e.g. lists) and pure functions don't. To my understanding modifier functions have a permanent influence on the memory (as they change the object directly) which would classify them as statements. The opposite should be true for pure functions. Therefore, my question is whether we can classify function calls generally into expressions and statements? Many thanks for your help in advance!
Great attention to detail you have. Generally, a mere function call is only an expression and should not have a side effect. However, as you noticed, we can create "modifier" functions that kind of have a side effect. However, such "modifier" functions should not be created in the first place (i.e., a best practice). Instead, one should create methods that modify objects. To fully understand that, see Chapter 11 in my book. But really, great attention to detail.
But what exactly makes the iterative version so efficient?
th eiterative approach is much more efficient because it only looks at the two predecessor numbers and does not need to store the other numbers in memory. Therefore, it needs less computing power and memory. The recursive approach looks at the whole thing and therefore needs exponential computing power which is a lot more inefficient and the reason why this approach only works with the smaller numbers. Hope this helps. Please correct me if I am wrong here @Alexander Hess - Pythonista
Kind of. The iterative version does all the individual computational steps only once whereas the recursive version re-computes the same individual steps over and over again.
Very good explanation of packing and unpacking! Especially the comparison to the zip() function and the use-case of swapping was beneficial to get a good understanding of when these principles can be helpful!
Glad you enjoyed it!
Thanks a lot Alex! The videos explained the contents in detail, and gives even more examples beside the lectures!
Glad it was helpful!
Great explanation on iterators and iterables! Especially the description on the "for loop behind the scenes" helped me a lot to get a better understanding.
Glad it was helpful! At first sight, iterators seem a bit "advanced" but they are really everywhere in Python and are very powerful in the context of big data.
Do I understand it correctly that all expressions are also statements?
Yes, but the reverse is not true. Expressions are all code fragments that are evaluated into objects (i.e., "results") by the Python interpreter. The concept of statements contains the concept of expressions in addition to statements that do NOT evaluate into objects. Such statements have a (permanent) side effect in the computer's memory though (e.g., the assignment statement creates a variable name).
@@webartifex had exactly the same question, thanks for clarifying
I really appreciated the time stamps in the previous video! Although they might not necessarily be needed in every video, I think it would be helpful especially for the sections where PythonTutor is being used
Noted!
You said, that we can classify concrete data types into abstract data types. Are abstract data types, by definition, always a "subset" of concrete data types with specific behavior (similar to the concepts of expressions and statements)?
Not really. In your picture, it is almost the opposite. The concrete ones are "subsets" of the abstract ones. Yet, the term "subset" is wrong here. For simplicity, see the abstract types as simply "group names", and the concrete ones are then put into various groups depending on their behavior.
Great explanation, maybe you can further explain how the hexadecimal codes come together, f.e. What 26 or 120 would look like, as this only shows quite „simple“ examples
Good idea. The next version of the videos will do that then.
The videos really helped to better understand Python next to the lectures. Thank you for your effort!
You're very welcome!
Is the binary number always the combination where you need the least 1s?
No. Or I misunderstand your question. Once there will be only more 0s to the left, the notation usually cuts them off, just like leading 0s in the decimal system.
It would be great if it could be briefly explained what effect it has on the outcome when print () is not indented, e.g. in the example: for number in numbers: result = number + 3 print (result) Other than that everything is explained very well in the video!
That is a good point. An absolute beginner may not understand the difference for indenting and not indenting. I'll take that into account for the next version :)
Instead of using the ‘elif’ statement, could two ‘if’ statements also be chained into one big one through an ‘and’ or is that just not done for readability purposes?
This really depends on the exact logic one wants to model. The point here is that the "elif"s are only checked if the preceeding "if" does not apply.
why is it possible to have two if statements and not elif in the second one? (min 22:50)
Because we are checking for conditions that are INDEPENDENT of each other, in a conceptually way. Also, note the "early exit pattern" at work in the example. So, I leave out a lot of "else"s and "return" from the function "early"
It was really clear to compare the difference between recursion and while looping with pythontutor!
To summarize: In terms of computational steps, there should not be much of a difference. In terms of memory usage: recursion needs some memory to keep all the functions running before the recursion returns. So, in practice, the looping approach is often regarded as a little better.
Thanks for the video :) I have a few questions haha. Will the !pip install command use your OS to create a new folder inside your python installation? And if so how does it know where to install it to? And how does the import statement know where to load the module from into memory? (i.e. when the current working directory is different from the file location) I assume it has to be some sort of relative mechanism as I as a user can individually determine where to initially install the anaconda distribution/ original python distribution.
There is no way to answer this question briefly :) For detailed info, search for "Python virtual environments" on the internet, or the "Python import system" (there is actually a nice but technical talk on a PyCon TH-cam channel on that). What you should know, in brief: 1) Besides the "system" Python (on Linux or Mac) which holds all packages available everywhere, there may exist 2) "copies" in so-called virtual enviroment, which are typically used on a per-project basis. 3) !pip in JupyterLab installs into whatever Python folder that is currently running JuypterLab. I should do a talk on this at some point because it's a topic of much confusion. Regarding the imports, they are indeed relative (or absolute) depending on how you import.
Very good and clear presentation of how this works in memory!
The practitioner may wonder why he should learn such things. But the binary system is at the heart of a lot of CS theory and I think is quite an interesting thing to know as a person living in the 21st century :)
One question regarding the memory: you mentioned, that if our computer runs out of memory, it would crash - Would that mean the program just closing itself without saving? And how much code “fits” in a regular computer’s memory before it is fully occupied?
What a program does when running out of memory depends a bit on the programming language. Typically one would observe a computer freezing, or at least the program in question becoming unresponsive. Yet, in Python there is a fail safe system built in that simply quits the program with a MemoryError message instead of the computer freezing. In both cases, the program most likely will not save anything permanently onto a hard disk and whatever data/state is in the (working) memory will then be lost.
Does the TypeError fall under runtime errors?
Absolutely, it is an error occuring during runtime. Yet, experienced Python dev's would tell you that there are actually ways to discover TypeError's WITHOUT running the code. But that is beyond this intro video.
When you talked about the limited size of the memory and that flowing objects usually have the same number of digits when they are infinite, you explained that there are usually 13 to 14 digits after the period dot. The example in the video shows 15 digits, and in the "Volume of a Sphere" exercises, our results never showed more than 10 digits. How come?
The answer to that needs some more theory that I think goes too much into detail. The correct answer is that the number of digits modeled in memory depends on the magnitude of the number. Numbers closer to 0 in abs. terms have more digits. Yet, it's a good practice to pretend there are only up to 14 digits as that is the lower bound that works for all floating-point numbers. If you are really interested in this, check the the wiki page on the floating-point standard :)