title
5 Common Python Mistakes and How to Fix Them
description
This video is sponsored by Skillshare. Be one of the first 500 people to sign up with this link and get 2 free months of Skillshare Premium:
https://skl.sh/coreyschafer2
In this Python Programming Tutorial, we will be going over some of the most common mistakes. I get a lot of questions from people every day, and I have seen a lot of people making these same mistakes in their code. So we will investigate each of these common mistakes and also look at the fixes for each other these as well. Here are the timestamps for each topic we will cover...
1) Indentation and Spaces - 0:45
2) Naming Conflicts - 4:12
3) Mutable Default Args - 10:05
4) Exhausting Iterators - 16:35
5) Importing with * - 22:13
PATH Tutorial - https://youtu.be/OdIHeg4jj2c
Iterators Tutorial - https://youtu.be/jTYiNjvnHZY
Generators Tutorial - https://youtu.be/bD05uGo_sVI
✅ Support My Channel Through Patreon:
https://www.patreon.com/coreyms
✅ Become a Channel Member:
https://www.youtube.com/channel/UCCezIgC97PvUuR4_gbFUs5g/join
✅ One-Time Contribution Through PayPal:
https://goo.gl/649HFY
✅ Cryptocurrency Donations:
Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot
✅ Corey's Public Amazon Wishlist
http://a.co/inIyro1
✅ Equipment I Use and Books I Recommend:
https://www.amazon.com/shop/coreyschafer
▶️ You Can Find Me On:
My Website - http://coreyms.com/
My Second Channel - https://www.youtube.com/c/coreymschafer
Facebook - https://www.facebook.com/CoreyMSchafer
Twitter - https://twitter.com/CoreyMSchafer
Instagram - https://www.instagram.com/coreymschafer/
#Python
detail
{'title': '5 Common Python Mistakes and How to Fix Them', 'heatmap': [{'end': 653.979, 'start': 594.475, 'weight': 0.779}, {'end': 797.195, 'start': 749.843, 'weight': 0.915}, {'end': 863.455, 'start': 819.852, 'weight': 0.807}, {'end': 978.63, 'start': 948.455, 'weight': 0.751}], 'summary': 'Covers 5 common mistakes in python programming, offering solutions and sponsored by skillshare. it discusses coding best practices, mutable default argument pitfalls, python iterators and zip function, and python imports best practices, emphasizing the impact on beginners and the importance of using an editor to avoid errors.', 'chapters': [{'end': 45.276, 'segs': [{'end': 34.21, 'src': 'embed', 'start': 0.209, 'weight': 0, 'content': [{'end': 6.073, 'text': "Hey there, how's it going everybody? So a few weeks ago, I released a video on 10 Python tips and tricks for writing better code.", 'start': 0.209, 'duration': 5.864}, {'end': 8.575, 'text': 'And a lot of you said that you found that video pretty helpful.', 'start': 6.453, 'duration': 2.122}, {'end': 12.798, 'text': "So in this video, I've compiled together another list of topics that I thought would be beneficial.", 'start': 8.935, 'duration': 3.863}, {'end': 17.821, 'text': "And that's the five most common mistakes I see from people when using Python and how to avoid those.", 'start': 13.238, 'duration': 4.583}, {'end': 21.683, 'text': 'Now I get questions every day from people who follow along with my videos,', 'start': 18.221, 'duration': 3.462}, {'end': 25.165, 'text': "and a lot of the questions have to do with the mistakes that we're going to discuss in this video.", 'start': 21.683, 'duration': 3.482}, {'end': 30.628, 'text': "And it's not always obvious what the problem is, so we're going to look at the cause and solution to all of these.", 'start': 25.525, 'duration': 5.103}, {'end': 34.21, 'text': "Now we do have a sponsor for this video and that's Skillshare.com.", 'start': 31.008, 'duration': 3.202}], 'summary': 'Compiled five common python mistakes and their solutions to help viewers write better code.', 'duration': 34.001, 'max_score': 0.209, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/zdJEYhA2AZQ/pics/zdJEYhA2AZQ209.jpg'}], 'start': 0.209, 'title': 'Common python mistakes', 'summary': 'Discusses the top 5 common mistakes in python programming, presenting solutions and promoting skillshare.com as a sponsor.', 'chapters': [{'end': 45.276, 'start': 0.209, 'title': 'Top 5 python mistakes & solutions', 'summary': 'Discusses the five most common mistakes in python programming and their solutions, addressing questions from viewers and promoting skillshare.com as a sponsor.', 'duration': 45.067, 'highlights': ['The chapter covers the five most common mistakes in Python programming and their solutions, addressing questions from viewers.', 'The video on 10 Python tips received positive feedback, leading to the compilation of this list of common mistakes.', 'The speaker promotes Skillshare.com as a sponsor and urges viewers to support the sponsors.', 'The chapter emphasizes the benefit of the topics discussed and mentions the positive reception of a previous video on Python tips and tricks.']}], 'duration': 45.067, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/zdJEYhA2AZQ/pics/zdJEYhA2AZQ209.jpg', 'highlights': ['The chapter covers the five most common mistakes in Python programming and their solutions, addressing questions from viewers.', 'The video on 10 Python tips received positive feedback, leading to the compilation of this list of common mistakes.', 'The chapter emphasizes the benefit of the topics discussed and mentions the positive reception of a previous video on Python tips and tricks.', 'The speaker promotes Skillshare.com as a sponsor and urges viewers to support the sponsors.']}, {'end': 594.094, 'segs': [{'end': 198.551, 'src': 'embed', 'start': 159.068, 'weight': 0, 'content': [{'end': 162.61, 'text': 'especially whenever everything just looks fine in your program at a glance.', 'start': 159.068, 'duration': 3.542}, {'end': 165.471, 'text': 'now, imagine that this module was a lot larger.', 'start': 163.03, 'duration': 2.441}, {'end': 172.055, 'text': 'we just have two indentations here, but imagine that we have, you know, 500 or 1000 lines of code.', 'start': 165.471, 'duration': 6.584}, {'end': 178.558, 'text': "it's going to be almost impossible to go through there and figure out which ones are using tabs and which ones are using spaces.", 'start': 172.055, 'duration': 6.503}, {'end': 186.242, 'text': "so instead of trying to go through and fix those manually, i would just highly recommend simply upgrading your editor or ide that you're using.", 'start': 178.558, 'duration': 7.684}, {'end': 191.185, 'text': 'so any good editor for python is going to be able to convert your tabs to spaces automatically.', 'start': 186.242, 'duration': 4.943}, {'end': 198.551, 'text': "So I'm using Sublime Text, but you can set this up in VS Code, PyCharm, Eclipse or whatever it is that you use.", 'start': 191.545, 'duration': 7.006}], 'summary': 'Upgrading editor/ide can convert tabs to spaces automatically, saving time and effort.', 'duration': 39.483, 'max_score': 159.068, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/zdJEYhA2AZQ/pics/zdJEYhA2AZQ159068.jpg'}, {'end': 288.331, 'src': 'embed', 'start': 263.059, 'weight': 2, 'content': [{'end': 270.803, 'text': 'your module with the same name takes higher priority than the modules from the standard library or the modules that you installed using pip.', 'start': 263.059, 'duration': 7.744}, {'end': 273.524, 'text': "So let's see an example of what this would look like.", 'start': 271.183, 'duration': 2.341}, {'end': 280.327, 'text': "So let's say that I have a project where I want to create a Python module that will do some mathematical calculations for me.", 'start': 273.904, 'duration': 6.423}, {'end': 284.229, 'text': "So I'm going to create a new module in my current directory.", 'start': 280.687, 'duration': 3.542}, {'end': 288.331, 'text': "So a new file here, and I'm just going to call this math.py.", 'start': 284.809, 'duration': 3.522}], 'summary': 'Creating a new module named math.py takes higher priority than standard library or pip-installed modules.', 'duration': 25.272, 'max_score': 263.059, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/zdJEYhA2AZQ/pics/zdJEYhA2AZQ263059.jpg'}, {'end': 424.603, 'src': 'embed', 'start': 399.206, 'weight': 3, 'content': [{'end': 405.954, 'text': "because if you can't import a module from the standard library, then it's pretty limited as to what the problems could be, and this is one of them.", 'start': 399.206, 'duration': 6.748}, {'end': 413.397, 'text': 'But if this was a package that we pip installed, like Flask or Django, then this could possibly take more time to figure out.', 'start': 406.334, 'duration': 7.063}, {'end': 419.9, 'text': "So there are a lot of times that I've tried to help people debug a problem where they're trying to write a Flask application or something like that.", 'start': 413.777, 'duration': 6.123}, {'end': 424.603, 'text': "And they have Flask installed, and they're using the right version of Python.", 'start': 420.401, 'duration': 4.202}], 'summary': 'Debugging standard library module issues is easier than debugging pip-installed packages.', 'duration': 25.397, 'max_score': 399.206, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/zdJEYhA2AZQ/pics/zdJEYhA2AZQ399206.jpg'}], 'start': 45.856, 'title': 'Python coding best practices', 'summary': 'Covers common python coding mistakes such as mixing tabs and spaces, and naming issues for modules and variables. it emphasizes the impact on beginners and the importance of using an editor to avoid such errors.', 'chapters': [{'end': 243.588, 'start': 45.856, 'title': 'Avoid mixing tabs and spaces', 'summary': 'Discusses the common mistake of mixing tabs and spaces in python, leading to indentation errors, particularly among beginners, and emphasizes the importance of using an editor that can convert tabs to spaces to avoid such errors.', 'duration': 197.732, 'highlights': ["It's a common mistake among beginners to mix tabs and spaces in Python, causing indentation errors, especially when using basic text editors (e.g., Sublime Text) (Relevance: 5)", 'Using an editor that automatically converts tabs to spaces, such as Sublime Text, VS Code, or PyCharm, can prevent these errors and ensure the correct execution of the program (Relevance: 4)', 'The chapter illustrates how mixing tabs and spaces can lead to an indentation error, even though the program appears correct, emphasizing the challenges of identifying and fixing such errors in larger modules (Relevance: 3)']}, {'end': 594.094, 'start': 243.588, 'title': 'Python module and variable naming issues', 'summary': 'Discusses the issues related to naming python modules and variables, highlighting the higher priority of a module with the same name, leading to import errors, and the potential conflicts from naming variables the same as imported functions.', 'duration': 350.506, 'highlights': ["Python modules with the same name as something to import takes higher priority, leading to import errors The module with the same name takes higher priority than the modules from the standard library or the modules installed using pip, causing import errors, as demonstrated by the example of naming a Python module 'math.py' and experiencing import errors while trying to import 'radians' and 'sin' from the standard library 'math' module.", "Naming variables the same as imported functions can lead to unexpected behavior and errors Naming a variable the same as an imported function can lead to unexpected behavior and errors, as shown by the example of naming a variable 'radians' and encountering issues when trying to use the 'radians' function further down in the code.", 'Naming conflicts can be difficult to debug, especially when dealing with pip-installed packages like Flask or Django Naming conflicts, especially with pip-installed packages like Flask or Django, can be challenging to debug and may require more time to identify, as highlighted by the difficulties in debugging import errors related to naming conflicts.']}], 'duration': 548.238, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/zdJEYhA2AZQ/pics/zdJEYhA2AZQ45856.jpg', 'highlights': ['Using an editor that automatically converts tabs to spaces can prevent indentation errors (Relevance: 4)', 'Mixing tabs and spaces can lead to indentation errors, emphasizing the challenges of identifying and fixing such errors in larger modules (Relevance: 3)', 'Python modules with the same name as something to import takes higher priority, leading to import errors (Relevance: 2)', 'Naming conflicts, especially with pip-installed packages like Flask or Django, can be challenging to debug (Relevance: 1)']}, {'end': 990.397, 'segs': [{'end': 661.164, 'src': 'heatmap', 'start': 594.475, 'weight': 2, 'content': [{'end': 604.763, 'text': 'So we can see if I simply name this something else like rad 90 or rads or something like that and run that, then we can see that now it works fine.', 'start': 594.475, 'duration': 10.288}, {'end': 610.167, 'text': "okay. so the next thing that I've seen some people get tripped up on is mutable default arguments,", 'start': 605.203, 'duration': 4.964}, {'end': 615.771, 'text': 'and I had an example of this in my object-oriented series, where I had a function that added employees to a list,', 'start': 610.167, 'duration': 5.604}, {'end': 624.957, 'text': "and a lot of people ask me why I just didn't pass in an empty list as a default argument and I told them it was because of this problem with mutable default arguments,", 'start': 615.771, 'duration': 9.186}, {'end': 627.719, 'text': "and we'll see why in an example here.", 'start': 624.957, 'duration': 2.762}, {'end': 630.061, 'text': "that's similar to the one that I had in that video.", 'start': 627.719, 'duration': 2.342}, {'end': 633.844, 'text': 'so let me close down my output here and also close my sidebar.', 'start': 630.061, 'duration': 3.783}, {'end': 637.006, 'text': 'So here we have a function called add employee.', 'start': 634.224, 'duration': 2.782}, {'end': 639.808, 'text': 'So let me explain what this function is meant to do.', 'start': 637.346, 'duration': 2.462}, {'end': 647.094, 'text': 'So it takes in a single employee and also an employee list as arguments.', 'start': 640.309, 'duration': 6.785}, {'end': 653.979, 'text': "And it's simply going to add that employee to this employee list and then print that list.", 'start': 647.614, 'duration': 6.365}, {'end': 661.164, 'text': 'but we can see here that the employee list has a default value equal to an empty list.', 'start': 653.979, 'duration': 7.185}], 'summary': 'Demonstrating issues with mutable default arguments in python functions.', 'duration': 23.818, 'max_score': 594.475, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/zdJEYhA2AZQ/pics/zdJEYhA2AZQ594475.jpg'}, {'end': 797.195, 'src': 'heatmap', 'start': 749.843, 'weight': 0.915, 'content': [{'end': 757.527, 'text': "So if I add another employee here and I'm still not providing an existing list, it should be creating a new list every time.", 'start': 749.843, 'duration': 7.684}, {'end': 766.233, 'text': 'but each time the list just gets longer and longer and keeps appending to the same list, even though we should have that empty list by default.', 'start': 757.907, 'duration': 8.326}, {'end': 773.958, 'text': "so what's going on here is that in Python, default arguments are evaluated once at the time it creates the function,", 'start': 766.233, 'duration': 7.725}, {'end': 779.701, 'text': "so it's not actually creating a new empty list each time we run the function.", 'start': 773.958, 'duration': 5.743}, {'end': 787.347, 'text': "now you won't notice this with immutable types like strings and things like that, but with mutable data types like a list in its,", 'start': 779.701, 'duration': 7.646}, {'end': 791.11, 'text': 'using the same list that it created when the function was defined.', 'start': 787.347, 'duration': 3.763}, {'end': 797.195, 'text': 'so what do, what do we do here if we want to be sure that we get an empty list each time?', 'start': 791.11, 'duration': 6.085}], 'summary': 'Python default arguments create one list, not a new one each time, leading to appending to same list.', 'duration': 47.352, 'max_score': 749.843, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/zdJEYhA2AZQ/pics/zdJEYhA2AZQ749843.jpg'}, {'end': 873.206, 'src': 'heatmap', 'start': 819.852, 'weight': 0, 'content': [{'end': 827.657, 'text': 'or you can say if not employee list either one, then we can create an employee list equal to a new empty list.', 'start': 819.852, 'duration': 7.805}, {'end': 834.726, 'text': 'So now that this is actually within the function, this will get run every time the function is run.', 'start': 829.458, 'duration': 5.268}, {'end': 839.412, 'text': 'Because like I said, these only get evaluated once when we initialize the function.', 'start': 835.046, 'duration': 4.366}, {'end': 844.119, 'text': 'So now, if I run this, then we can see that it works as expected.', 'start': 839.773, 'duration': 4.346}, {'end': 846.222, 'text': 'It creates a new empty list.', 'start': 844.319, 'duration': 1.903}, {'end': 849.885, 'text': 'each time we add an employee without an existing employee list.', 'start': 846.562, 'duration': 3.323}, {'end': 853.267, 'text': 'And this should still work the same as before as well.', 'start': 850.265, 'duration': 3.002}, {'end': 859.992, 'text': 'If we do provide an employee list already, then it just gets tacked on to that existing list.', 'start': 853.427, 'duration': 6.565}, {'end': 863.455, 'text': 'So this is how you do mutable default arguments.', 'start': 860.172, 'duration': 3.283}, {'end': 866.759, 'text': "Now this doesn't only give us unexpected problems with lists.", 'start': 863.815, 'duration': 2.944}, {'end': 873.206, 'text': 'When I said that default arguments are executed once when the function is created and not each time the function is called,', 'start': 867.239, 'duration': 5.967}], 'summary': 'Code demonstrates setting mutable default arguments within a function, showing how it creates a new empty list each time an employee is added without an existing list, and tacks on to the existing list if one is provided.', 'duration': 22.941, 'max_score': 819.852, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/zdJEYhA2AZQ/pics/zdJEYhA2AZQ819852.jpg'}, {'end': 989.216, 'src': 'heatmap', 'start': 943.791, 'weight': 3, 'content': [{'end': 948.455, 'text': "But we can see that each time it ran, it didn't update the time like you might expect now.", 'start': 943.791, 'duration': 4.664}, {'end': 955.439, 'text': 'the reason, just like before, is because it only executes those default arguments once when the function is declared,', 'start': 948.455, 'duration': 6.984}, {'end': 957.78, 'text': 'and not each time the function is run.', 'start': 955.439, 'duration': 2.341}, {'end': 964.123, 'text': 'so again, in order to do this, we would instead just need to move this into the function itself,', 'start': 957.78, 'duration': 6.343}, {'end': 978.63, 'text': "so I could do something like this I could just say time is equal to none, And if time is none, then let's just set the time equal to datetime.now.", 'start': 964.123, 'duration': 14.507}, {'end': 989.216, 'text': 'So now, if I run this, then we can see that it sleeps one second between the function calls, but it actually got the current time,', 'start': 979.151, 'duration': 10.065}], 'summary': "Default arguments are only executed once when the function is declared, not each time it's run.", 'duration': 45.425, 'max_score': 943.791, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/zdJEYhA2AZQ/pics/zdJEYhA2AZQ943791.jpg'}], 'start': 594.475, 'title': 'Mutable default argument pitfalls', 'summary': 'Discusses the problems with mutable default arguments in python functions, showing how the default argument is evaluated once and retained across multiple calls, leading to unexpected behavior like reusing the same list object and not updating the default time value.', 'chapters': [{'end': 773.958, 'start': 594.475, 'title': 'Mutable default arguments in python', 'summary': 'Explains the problem with mutable default arguments in python functions, demonstrating how the default argument is evaluated once and retained across multiple calls, leading to unexpected behavior.', 'duration': 179.483, 'highlights': ['The chapter explains the problem with mutable default arguments in Python functions, demonstrating how the default argument is evaluated once and retained across multiple calls, leading to unexpected behavior. This is the main point of the chapter, highlighting the issue with mutable default arguments in Python functions and how it can lead to unexpected behavior when the default argument is evaluated once and retained across multiple calls.', "The function 'add_employee' takes in a single employee and an employee list as arguments, adding the employee to the list and printing it. Explains the purpose of the 'add_employee' function, which takes a single employee and an employee list as arguments, adds the employee to the list, and then prints the updated list.", 'Demonstrates the unexpected behavior of mutable default arguments by showing how the empty list default value is retained across multiple function calls, leading to the list being extended instead of reset. Illustrates the unexpected behavior of mutable default arguments by demonstrating how the empty list default value is retained across multiple function calls, resulting in the list being extended instead of reset, contrary to the expected behavior.']}, {'end': 990.397, 'start': 773.958, 'title': 'Mutable default argument pitfalls', 'summary': 'Highlights the issue of mutable default arguments in python functions, demonstrating with examples how default arguments are executed once when the function is created and not each time the function is called, leading to unexpected behavior, such as reusing the same list object and not updating the default time value.', 'duration': 216.439, 'highlights': ['The chapter explains how mutable default arguments in Python functions can lead to unexpected behavior, such as reusing the same list object and not updating the default time value.', 'The function demonstrates how using a mutable default argument like a list in Python can lead to unexpected behavior, as the same list object is reused when the function is called.', 'The example with the datetime.now default argument shows how default arguments are executed once when the function is created and not each time the function is called, resulting in the default time value not being updated.']}], 'duration': 395.922, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/zdJEYhA2AZQ/pics/zdJEYhA2AZQ594475.jpg', 'highlights': ['The chapter explains the problem with mutable default arguments in Python functions, demonstrating how the default argument is evaluated once and retained across multiple calls, leading to unexpected behavior.', 'Illustrates the unexpected behavior of mutable default arguments by demonstrating how the empty list default value is retained across multiple function calls, resulting in the list being extended instead of reset, contrary to the expected behavior.', "The function 'add_employee' takes in a single employee and an employee list as arguments, adding the employee to the list and printing it.", 'The example with the datetime.now default argument shows how default arguments are executed once when the function is created and not each time the function is called, resulting in the default time value not being updated.']}, {'end': 1329.405, 'segs': [{'end': 1028.801, 'src': 'embed', 'start': 990.657, 'weight': 0, 'content': [{'end': 995.06, 'text': 'So actually knowing how those default arguments work is one thing that I see that trips up a lot of people.', 'start': 990.657, 'duration': 4.403}, {'end': 999.482, 'text': 'Okay. so moving on another question that I get asked a lot,', 'start': 995.66, 'duration': 3.822}, {'end': 1005.526, 'text': "and a common mistake that I see is when people don't fully understand how iterators work and how they're exhausted.", 'start': 999.482, 'duration': 6.044}, {'end': 1015.352, 'text': 'So this is especially true with a lot of people moving from Python 2 over to Python 3, because more things within Python 3 now behave like generators,', 'start': 1005.907, 'duration': 9.445}, {'end': 1018.755, 'text': 'because those are more efficient, but it does cause people some confusion.', 'start': 1015.352, 'duration': 3.403}, {'end': 1021.336, 'text': "So let's take a look at what I mean here.", 'start': 1019.115, 'duration': 2.221}, {'end': 1023.958, 'text': 'So let me close down the output down here.', 'start': 1021.656, 'duration': 2.302}, {'end': 1028.801, 'text': "So within this file, I'm using an example that I've used in videos before.", 'start': 1024.678, 'duration': 4.123}], 'summary': 'Understanding default arguments and iterators is crucial for python 3 transition.', 'duration': 38.144, 'max_score': 990.657, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/zdJEYhA2AZQ/pics/zdJEYhA2AZQ990657.jpg'}, {'end': 1168.194, 'src': 'embed', 'start': 1139.734, 'weight': 1, 'content': [{'end': 1143.896, 'text': 'But with things like zip, they might behave a bit differently.', 'start': 1139.734, 'duration': 4.162}, {'end': 1146.897, 'text': "So now I've switched over to using Python 3.", 'start': 1144.216, 'duration': 2.681}, {'end': 1148.858, 'text': 'And now let me run this same code.', 'start': 1146.897, 'duration': 1.961}, {'end': 1150.819, 'text': 'So it kind of looks the same.', 'start': 1149.298, 'duration': 1.521}, {'end': 1153.502, 'text': 'We still are looping through the values here.', 'start': 1151.2, 'duration': 2.302}, {'end': 1162.289, 'text': 'But now whenever we printed out these identities, we instead get this zip object instead of that entire list of those zipped items.', 'start': 1153.862, 'duration': 8.427}, {'end': 1168.194, 'text': "So what's going on here is that Python 3 no longer returns all of those values at once.", 'start': 1162.649, 'duration': 5.545}], 'summary': 'Switched to python 3 for different behavior in zip function.', 'duration': 28.46, 'max_score': 1139.734, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/zdJEYhA2AZQ/pics/zdJEYhA2AZQ1139734.jpg'}, {'end': 1274.924, 'src': 'embed', 'start': 1247.905, 'weight': 2, 'content': [{'end': 1255.351, 'text': "So here we're converting our zip object to a list and then trying to loop over that same zip object again.", 'start': 1247.905, 'duration': 7.446}, {'end': 1262.076, 'text': "But we've already exhausted the zip object when we converted it to a list at this line here.", 'start': 1255.711, 'duration': 6.365}, {'end': 1268.06, 'text': 'When we did this, it looped through all those values and converted them to a list and then we printed them out.', 'start': 1262.396, 'duration': 5.664}, {'end': 1274.924, 'text': "So now when we're trying to loop over that here, it's not working because this has been exhausted and there's no more values left here.", 'start': 1268.46, 'duration': 6.464}], 'summary': 'Converting zip object to list exhausted values, preventing further looping.', 'duration': 27.019, 'max_score': 1247.905, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/zdJEYhA2AZQ/pics/zdJEYhA2AZQ1247905.jpg'}], 'start': 990.657, 'title': 'Python iterators and zip function', 'summary': 'Covers common mistakes and confusion around default arguments and iterators in python, particularly when transitioning from python 2 to python 3, along with the usage of the zip function in python 2 and python 3, and how to work around issues related to exhausted iterators.', 'chapters': [{'end': 1028.801, 'start': 990.657, 'title': 'Understanding default arguments and iterators', 'summary': 'Covers common mistakes and confusion around default arguments and iterators in python, particularly when transitioning from python 2 to python 3, which causes confusion due to the behavior of generators and exhaustion of iterators.', 'duration': 38.144, 'highlights': ['Understanding how default arguments work is a common challenge for many people.', 'The confusion around iterators is especially prevalent when transitioning from Python 2 to Python 3 due to the behavior of generators and exhaustion of iterators.']}, {'end': 1329.405, 'start': 1029.222, 'title': 'Python zip function and iterators', 'summary': 'Discusses the usage of the zip function in python 2 and python 3, highlighting the differences in behavior and the concept of iterators being exhausted, ultimately demonstrating how to work around these issues to achieve the desired results.', 'duration': 300.183, 'highlights': ['Python 3 no longer returns all zipped values at once, leading to the output of a zip object instead of a list, affecting the looping process. In Python 3, when using the zip function, it returns a zip object instead of a list, altering the looping process, which may cause confusion for users accustomed to Python 2. This behavior change affects the efficient usage of memory and looping mechanisms.', 'Converting the zip object to a list allows for the retrieval of all zipped items and enables looping over the list without exhaustion. By converting the zip object to a list, all zipped items can be retrieved, and looping over the list becomes possible without exhaustion. This approach ensures that the values can be printed and looped over as desired, resembling the behavior in Python 2.', 'The concept of iterators being exhausted is explained, emphasizing the need to understand this behavior for efficient utilization. The concept of iterators being exhausted is elucidated, underscoring the importance of comprehending this behavior to efficiently utilize iterators in Python. Understanding this concept is crucial for handling differences in behavior between Python 2 and Python 3 when using functions like zip.']}], 'duration': 338.748, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/zdJEYhA2AZQ/pics/zdJEYhA2AZQ990657.jpg', 'highlights': ['The confusion around iterators is prevalent when transitioning from Python 2 to Python 3.', 'Python 3 returns a zip object instead of a list when using the zip function, affecting looping.', 'Converting the zip object to a list allows for retrieval of all zipped items and enables looping without exhaustion.', 'Understanding the concept of iterators being exhausted is crucial for efficient utilization.']}, {'end': 1746.427, 'segs': [{'end': 1403.039, 'src': 'embed', 'start': 1375.77, 'weight': 1, 'content': [{'end': 1384.278, 'text': "so for every function from the OS module I would have to say OS dot and then the function name, like we're doing here, OS dot rename.", 'start': 1375.77, 'duration': 8.508}, {'end': 1389.545, 'text': "But we can also import functions one at a time to where we don't need to use OS dot.", 'start': 1384.539, 'duration': 5.006}, {'end': 1397.775, 'text': 'So for example, if I just wanted to use rename a file name, then instead I could say from OS import.', 'start': 1389.805, 'duration': 7.97}, {'end': 1403.039, 'text': 'rename and now we no longer need to say os.rename.', 'start': 1398.496, 'duration': 4.543}], 'summary': "To use os module functions, import them directly to avoid using 'os dot' every time.", 'duration': 27.269, 'max_score': 1375.77, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/zdJEYhA2AZQ/pics/zdJEYhA2AZQ1375770.jpg'}, {'end': 1465.072, 'src': 'embed', 'start': 1423.651, 'weight': 0, 'content': [{'end': 1428.394, 'text': 'now we can also use an asterisk on the import to just simply import everything.', 'start': 1423.651, 'duration': 4.743}, {'end': 1432.416, 'text': "But this is a bad practice most of the time, unless you really know what you're doing.", 'start': 1428.774, 'duration': 3.642}, {'end': 1436.357, 'text': 'But sometimes, people just want to be able to use everything and not think about it.', 'start': 1433.016, 'duration': 3.341}, {'end': 1441.42, 'text': "So they'll just come up here and say, from OS, import asterisk, import star.", 'start': 1436.657, 'duration': 4.763}, {'end': 1450.824, 'text': 'And that will allow us to use rename and remove and anything else that is in the OS module without using OS dot.', 'start': 1441.84, 'duration': 8.984}, {'end': 1455.866, 'text': 'OK, but why is this a bad practice? So first of all, it can make your code hard to debug.', 'start': 1451.184, 'duration': 4.682}, {'end': 1465.072, 'text': 'So if our module was 500 lines of code here and halfway down I use this rename function then other people reading our code, or even us in the future,', 'start': 1456.306, 'duration': 8.766}], 'summary': 'Using asterisk for imports can make code hard to debug and is generally a bad practice', 'duration': 41.421, 'max_score': 1423.651, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/zdJEYhA2AZQ/pics/zdJEYhA2AZQ1423651.jpg'}, {'end': 1579.324, 'src': 'embed', 'start': 1553.869, 'weight': 3, 'content': [{'end': 1560.45, 'text': "So by importing using these asterisks, it's just extremely easy to confuse people reading your code and it's a pain to debug.", 'start': 1553.869, 'duration': 6.581}, {'end': 1563.011, 'text': 'And also it can cause issues like this.', 'start': 1560.77, 'duration': 2.241}, {'end': 1571.878, 'text': "So anytime you need to actually import from a module, then it's better to instead just import it explicitly.", 'start': 1563.831, 'duration': 8.047}, {'end': 1579.324, 'text': 'So if I wanted to import both of these, then I could just say import escape and import escape.', 'start': 1572.198, 'duration': 7.126}], 'summary': 'Importing using asterisks causes confusion and debugging issues. explicit imports are better.', 'duration': 25.455, 'max_score': 1553.869, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/zdJEYhA2AZQ/pics/zdJEYhA2AZQ1553869.jpg'}, {'end': 1656.656, 'src': 'embed', 'start': 1628.012, 'weight': 5, 'content': [{'end': 1635.197, 'text': 'Skillshare is an online learning community with more than 25, 000 classes in tech, business, design, and a lot of other topics.', 'start': 1628.012, 'duration': 7.185}, {'end': 1639.981, 'text': 'They have over 7 million students so far, and they have new courses coming out on a regular basis.', 'start': 1635.518, 'duration': 4.463}, {'end': 1644.004, 'text': 'Now my audience would most likely be interested in their programming courses.', 'start': 1640.361, 'duration': 3.643}, {'end': 1648.989, 'text': 'and you can see here that they have classes in data science, data visualization.', 'start': 1644.444, 'duration': 4.545}, {'end': 1656.656, 'text': 'they have some courses in introduction to programming and computer science, deep learning and neural networks using Python.', 'start': 1648.989, 'duration': 7.667}], 'summary': 'Skillshare offers 25,000+ classes, serving 7m+ students, including programming courses in data science, data visualization, introduction to programming, computer science, deep learning, and neural networks using python.', 'duration': 28.644, 'max_score': 1628.012, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/zdJEYhA2AZQ/pics/zdJEYhA2AZQ1628012.jpg'}], 'start': 1329.405, 'title': 'Python imports best practices', 'summary': 'Discusses the drawbacks of using asterisk imports in python, highlighting potential debugging issues and namespace clutter, emphasizes the importance of importing modules explicitly, and provides alternative import methods. additionally, the video is sponsored by skillshare, with a special offer for the first 500 sign-ups.', 'chapters': [{'end': 1441.42, 'start': 1329.405, 'title': 'Python imports best practices', 'summary': 'Discusses the best practices for python imports, highlighting the problems of using asterisk to import everything from a module and the benefits of importing specific functions to avoid namespace clutter and potential debugging issues.', 'duration': 112.015, 'highlights': ['Using asterisk for imports is a bad practice as it imports everything from a module, leading to namespace clutter and potential debugging issues. Importing everything from a module using an asterisk can lead to namespace clutter and potential debugging issues, as every function from the module will need to be prefixed with the module name, causing code readability and maintainability problems.', 'Importing specific functions one at a time can avoid the need to use module prefixes and simplify the code. Importing specific functions one at a time from a module can simplify the code and avoid the need to use module prefixes, enhancing code readability and maintainability.', 'Using asterisk for imports should be avoided unless the user has a clear understanding of its implications. Using asterisk for imports should be avoided unless the user has a clear understanding of its implications, as it can lead to namespace clutter and potential debugging issues if not used carefully.']}, {'end': 1746.427, 'start': 1441.84, 'title': 'Avoiding asterisk imports in python', 'summary': 'Discusses the drawbacks of using asterisk imports in python, such as making code hard to debug, potentially introducing errors with functions of the same name, and causing confusion for readers. it emphasizes the importance of importing modules explicitly and provides examples of alternative import methods. additionally, the video is sponsored by skillshare, with a special offer for the first 500 sign-ups.', 'duration': 304.587, 'highlights': ['The drawbacks of using asterisk imports in Python It makes code hard to debug and can introduce errors with functions of the same name.', 'Importing modules explicitly is emphasized Explicit import methods are recommended to avoid confusion and code obfuscation.', 'Sponsorship by Skillshare with a special offer for the first 500 sign-ups Skillshare is promoted as a sponsor with a special offer for the first 500 sign-ups.']}], 'duration': 417.022, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/zdJEYhA2AZQ/pics/zdJEYhA2AZQ1329405.jpg', 'highlights': ['Using asterisk for imports is a bad practice as it imports everything from a module, leading to namespace clutter and potential debugging issues.', 'Importing specific functions one at a time can avoid the need to use module prefixes and simplify the code.', 'Using asterisk for imports should be avoided unless the user has a clear understanding of its implications.', 'Explicit import methods are recommended to avoid confusion and code obfuscation.', 'It makes code hard to debug and can introduce errors with functions of the same name.', 'Skillshare is promoted as a sponsor with a special offer for the first 500 sign-ups.']}], 'highlights': ['The chapter covers the five most common mistakes in Python programming and their solutions, addressing questions from viewers.', 'The video on 10 Python tips received positive feedback, leading to the compilation of this list of common mistakes.', 'The chapter emphasizes the benefit of the topics discussed and mentions the positive reception of a previous video on Python tips and tricks.', 'The speaker promotes Skillshare.com as a sponsor and urges viewers to support the sponsors.', 'Using an editor that automatically converts tabs to spaces can prevent indentation errors (Relevance: 4)', 'Mixing tabs and spaces can lead to indentation errors, emphasizing the challenges of identifying and fixing such errors in larger modules (Relevance: 3)', 'Python modules with the same name as something to import takes higher priority, leading to import errors (Relevance: 2)', 'Naming conflicts, especially with pip-installed packages like Flask or Django, can be challenging to debug (Relevance: 1)', 'The chapter explains the problem with mutable default arguments in Python functions, demonstrating how the default argument is evaluated once and retained across multiple calls, leading to unexpected behavior.', 'Illustrates the unexpected behavior of mutable default arguments by demonstrating how the empty list default value is retained across multiple function calls, resulting in the list being extended instead of reset, contrary to the expected behavior.', "The function 'add_employee' takes in a single employee and an employee list as arguments, adding the employee to the list and printing it.", 'The example with the datetime.now default argument shows how default arguments are executed once when the function is created and not each time the function is called, resulting in the default time value not being updated.', 'The confusion around iterators is prevalent when transitioning from Python 2 to Python 3.', 'Python 3 returns a zip object instead of a list when using the zip function, affecting looping.', 'Converting the zip object to a list allows for retrieval of all zipped items and enables looping without exhaustion.', 'Understanding the concept of iterators being exhausted is crucial for efficient utilization.', 'Using asterisk for imports is a bad practice as it imports everything from a module, leading to namespace clutter and potential debugging issues.', 'Importing specific functions one at a time can avoid the need to use module prefixes and simplify the code.', 'Using asterisk for imports should be avoided unless the user has a clear understanding of its implications.', 'Explicit import methods are recommended to avoid confusion and code obfuscation.', 'It makes code hard to debug and can introduce errors with functions of the same name.', 'Skillshare is promoted as a sponsor with a special offer for the first 500 sign-ups.']}