Skip to content
Discussion options

You must be logged in to vote

Both flags are worth raising, and they're separable:

1. insert(3, 'pink') against a hardcoded shape — yes, fragile. The intent (from the output order) is "pink lands right before vintage." Index 3 only happens to encode that because the list is 4 long at that moment. Intent-preserving alternatives:

colors.insert(colors.index("vintage"), "pink")  # "before vintage", by name
colors.insert(-1, "pink")                         # "before the last element"

With the current sequence both are equivalent to insert(3, ...) — but they survive future appends above, which is exactly your concern. insert(-1, ...) is the smallest change; index("vintage") is the most self-documenting.

2. The tuple unpack …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by dab00gieman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants