Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use Python to calculate a person's constellation

Shulou Source: shulou.com Published: 2022-06-01 04:08:33 10月04日 Update

This article mainly explains "how to use Python to calculate a person's constellation". Friends who are interested might as well take a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to use Python to calculate a person's constellation"!

Pass the month and date of birth into this function, and you can get the corresponding constellation. Of course, this is only a very simple first step. Next, let's calculate which star sign has the most people in the top 100 of the global rich list in 2012. Hee hee, do you expect it?

1. Get data

There is a post on Douban that helps us list the corresponding data, but in the form of text:

Https://www.douban.com/group/topic/28671832/

Fortunately, there is a unified format, and we can extract the date of birth with regular expressions:

(\ d +)? Month? (\ d +)? Day

In Vscode, you can also directly replace it with a pattern to become the tuple we want:

Click enter to replace it with a tuple. In the end, we will find that there are only 88 birth dates, it doesn't matter, it's enough for our experiment.

two。 Put the code into the calculation

Put all the dates you got earlier into an array, and then call the constellation calculation function we said at the beginning, of course, you need to use a dictionary to calculate the occurrence of each constellation:

Because there is too much data here, I didn't cut it up. Interested friends can Python practical treasure official account background reply constellation tycoon calculation to get all the data and code.

The results are as follows:

{Aquarius: 7, Scorpio: 7, Virgo: 8, Pisces: 7, Aries: 12, Leo: 8, Libra: 5, Taurus: 9, Cancer: 1, Gemini: 5, Capricorn: 3, Sagittarius: 4}

Let's make a sequence:

Print (sorted (result.items (), key=lambda item: item [1]))

Results:

(cancer, 1), (Capricorn, 3), (Sagittarius, 4), (Libra, 5), (Gemini, 5), (Aquarius, 7), (Scorpio, 7), (Pisces, 7), (Virgo, 8), (Leo, 8), (Taurus, 9), (Aries, 12)]

At this point, I believe you have a deeper understanding of "how to use Python to calculate a person's constellation". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Constellation data personal form date practical Code interest content function Gemini Gemini Pisces Virgo Libra Scorpio Sagittarius Friends Aquarius Leo Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei OPPO Reno Shulou Technology macOS MySQL