In your question, it is not the number of times something is mentioned, rather
A
is used when being nonspecific, whereas
The
is used when being specific or pointing out uniqueness or utmost
I'm going to tell you about a city called Tripoli.
The city (that I just mentioned) has lots of beautiful houses.
"the city" is used since you are specifying the city you just mentioned in the previous sentence
This is a different pattern to
I'm going to tell you about a city called Tripoli.
It is a city with lots of beautiful houses.
It is also a city with pre-Roman and pre-Ottoman architecture.
It is the most famous and largest city in LybiaLebanon.
Where there are many cities with "beautiful houses" and "architecture", but only one is the "*largest" and "most famous".
The ordering could be changed to
I'm going to tell you about a city called Tripoli.
It is the most famous and largest city in LybiaLebanon.
It is a city with lots of beautiful houses.
It is also a city with pre-Roman and pre-Ottoman architecture.
A native speaker would not have a problem with either ordering.
Maybe this makes it clearer the difference in using "the" vs "a", but it is not dependent on the "ordering".