Best Coding Practices – Plurals When Naming List Variables
When you are naming variables that contain a list object using the plural form of what it represents is more straightforward and easy to read. Here are some insights on naming list variables.
For example, when you have a list of users and you’d want to iterate through it. You’d write something like this.
for user in users:
print(user)
The for user in users
is better than for user in user_list
.
But sometimes you would come across unquantifiable nouns like news
. In that case, you would have to use news_list
.
But please do not, forever, for as long as the universe exists, use something like for news in News
. This should be punished severely.
This post was first published on July 29, 2012.