Is it better not to name list variables “list”? Since it’s conflicted with the python reserved keyword. Then, what’s the better naming? “input_list” sounds kinda awkward.
I know it can be problem-specific, but, say I have a quick sort function, then quick_sort(unsorted_list) is still kinda lengthy, since list passed to sorting function is clearly unsorted by context.
Any idea?
I like to name it with the plural of whatever’s in it. So, for example, if I have a list of names, I call it
names, and then I can write:which I think looks pretty nice. But generally for your own sanity you should name your variables so that you can know what they are just from the name. This convention has the added benefit of being type-agnostic, just like Python itself, because
namescan be any iterable object such as a tuple, a dict, or your very own custom (iterable) object. You can usefor name in nameson any of those, and if you had a tuple callednames_listthat would just be weird.(Added from a comment below:) There are a few situations where you don’t have to do this. Using a canonical variable like
ito index a short loop is OK becauseiis usually used that way. If your variable is used on more than one page worth of code, so that you can’t see its entire lifetime at once, you should give it a sensible name.