Is there an idiom which expresses the idea of "getting a good result from a bad situation or with a bad condition"? Thanks!
A well-worn way to put this is: When life gives you lemons, make lemonade.
Or, to match your question: Making lemonade when life has given you lemons.
It may not be quite right for you, since it is often used as a prod towards positive thinking, rather than a statement of results.
I suggest to make the best of a bad situation
To deal with and create the best possible outcome of a bad, unfortunate, or unpleasant situation or set of circumstances
The cliché happy ending also could work as an alternative.
It originally was used to describe the common plotline of novels in which everything turned out well for the protagonist after a bad situation, but it is used now as an idiom to mean 'it all turned out well'.
"Flipping the script"
flip the script (third-person singular simple present flips the script, present participle flipping the script, simple past and past participle flipped the script)
(slang) To reverse a situation, especially by doing something unexpected.