Python sympy | sieve.mobiusrange() method

With the help of sympy.sieve.mobiusrange() method, we can generate the mobius numbers for a given range [a, b). It returns a type generator object which can be converted to a list for further operations.

Syntax: sieve.mobiusrange(a, b)
Parameters:
a – It denotes the start of the range. It is inclusive.
b – It denotes the end of the range. It is not inclusive.
Returns: The method returns a type generator object.

Example #1:



filter_none

edit
close

play_arrow

link
brightness_4
code

# import sympy 
from sympy import sieve
  
# Use sieve.mobiusrange() method 
mobius_gen = sieve.mobiusrange(1, 10
mobius_list = list(mobius_gen)
      
print("Mobius numbers for the range of numbers [1, 10) : {}".format(mobius_list))  

chevron_right


Output:

Mobius numbers for the range of numbers [1, 10) : [1, -1, -1, 0, -1, 1, -1, 0, 0]

Example #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# import sympy 
from sympy import sieve
  
# Use sieve.mobiusrange() method 
mobius_gen = sieve.mobiusrange(8, 20
mobius_list = list(mobius_gen)
      
print("Mobius numbers for the range of numbers [8, 20) : {}".format(mobius_list))     

chevron_right


Output:

Mobius numbers for the range of numbers [8, 20) : [0, 0, 1, -1, 0, -1, 1, 1, 0, -1, 0, -1]


My Personal Notes arrow_drop_up

Coder Machine Learner Social Activist Vocalist

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.