From 1d1ebf540d63464da053d4e4f3c0e5d755b2cd82 Mon Sep 17 00:00:00 2001 From: Marc Poulin Date: Fri, 14 Sep 2018 11:20:53 -0600 Subject: [PATCH] Side effects of changing a list --- docs/writing/style.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/writing/style.rst b/docs/writing/style.rst index 1ff8382..9fde6b9 100644 --- a/docs/writing/style.rst +++ b/docs/writing/style.rst @@ -610,7 +610,7 @@ The approach you use depends on * Python 2.x vs. 3.x * Lists vs. iterators -* Creating a new list vs. modifying the original list +* Possible side effects of modifying the original list Python 2.x vs. 3.x :::::::::::::::::: @@ -644,7 +644,7 @@ Creating a new list requires more work and uses more memory. If you a just going # Or (2.x) filtered_values = filter(lambda i: i != x, sequence) - # generators are lazy + # generators don't create another list filtered_values = (value for value in sequence if value != x) # Or (3.x) filtered_values = filter(lambda i: i != x, sequence) @@ -653,8 +653,8 @@ Creating a new list requires more work and uses more memory. If you a just going -Creating a new list vs. modifying the original list -::::::::::::::::::::::::::::::::::::::::::::::::::: +Possible side effects of modifying the original list +:::::::::::::::::::::::::::::::::::::::::::::::::::: Modifying the original list can be risky if there are other variables referencing it. But you can use *slice assignment* if you really want to do that.