Generate Python code that has the following intention.

The intention of the code p1(n) is to count the number of set bits in the binary representation of the integer n.

The code uses a while loop to repeatedly apply the bitwise XOR operation to n with n-1, which flips any set bits in n. The number of times the while loop iterates is counted by the count variable, and this count represents the number of set bits in n.

Finally, the count variable is returned as the result of the function p1(n). Do not include the following keywords: p1(n, result, generate, n.
user