In this article we will see how we can get the number of lists a user has been added to. The listed_count attribute provides us with an integer denoting the number of public lists a user has been added to. Private lists are not counted.
In order to get the number number of public lists a user has been added to, we have to do the following :
- Identify the user ID or the screen name of the profile.
- Get the User object of the profile using the
get_user() method with the user ID or the screen name.
- From this object, fetch the listed_count attribute present in it.
Example 1: Consider the following profile :
👁 Image
We will use the user ID to fetch the user. The user ID of the above mentioned profile is 57741058.
Output :
The number of lists the user has been added to are : 141
Example 2: Consider the following profile :
👁 Image
We will use the screen name to fetch the user. The screen name of the above mentioned profile is PracticeGfG.