Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tutorial: 4.2. for Statements #82239

Closed
Derangedn00b mannequin opened this issue Sep 8, 2019 · 1 comment
Closed

Tutorial: 4.2. for Statements #82239

Derangedn00b mannequin opened this issue Sep 8, 2019 · 1 comment
Labels
3.7 (EOL) end of life build The build process and cross-build docs Documentation in the Doc dir

Comments

@Derangedn00b
Copy link
Mannequin

Derangedn00b mannequin commented Sep 8, 2019

BPO 38058

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2019-09-08.16:17:16.279>
created_at = <Date 2019-09-08.16:13:34.921>
labels = ['invalid', 'build', '3.7', 'docs']
title = 'Tutorial: 4.2. for Statements'
updated_at = <Date 2019-09-08.16:17:16.279>
user = 'https://bugs.python.org/Derangedn00b'

bugs.python.org fields:

activity = <Date 2019-09-08.16:17:16.279>
actor = 'Derangedn00b'
assignee = 'docs@python'
closed = True
closed_date = <Date 2019-09-08.16:17:16.279>
closer = 'Derangedn00b'
components = ['Documentation']
creation = <Date 2019-09-08.16:13:34.921>
creator = 'Derangedn00b'
dependencies = []
files = []
hgrepos = []
issue_num = 38058
keywords = []
message_count = 1.0
messages = ['351331']
nosy_count = 2.0
nosy_names = ['docs@python', 'Derangedn00b']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'compile error'
url = 'https://bugs.python.org/issue38058'
versions = ['Python 3.7']

@Derangedn00b
Copy link
Mannequin Author

Derangedn00b mannequin commented Sep 8, 2019

>>> # Measure some strings:
... words = ['cat', 'window', 'defenestrate']
>>> for w in words:
...     print(w, len(w))
...
cat 3
window 6
defenestrate 12

If you need to modify the sequence you are iterating over while inside the loop (for example to duplicate selected items), it is recommended that you first make a copy. Iterating over a sequence does not implicitly make a copy. The slice notation makes this especially convenient:

>>>>>> for w in words[:]:  # Loop over a slice copy of the entire list.
...     if len(w) > 6:
...         words.insert(0, w)
...
>>> words
['defenestrate', 'cat', 'window', 'defenestrate']

words is a tuple and is immutable

@Derangedn00b Derangedn00b mannequin added the 3.7 (EOL) end of life label Sep 8, 2019
@Derangedn00b Derangedn00b mannequin assigned docspython Sep 8, 2019
@Derangedn00b Derangedn00b mannequin added docs Documentation in the Doc dir build The build process and cross-build labels Sep 8, 2019
@Derangedn00b Derangedn00b mannequin closed this as completed Sep 8, 2019
@Derangedn00b Derangedn00b mannequin added the invalid label Sep 8, 2019
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life build The build process and cross-build docs Documentation in the Doc dir
Projects
None yet
Development

No branches or pull requests

0 participants