擅长:python、mysql、java
<p>也许您可以使用<code>while True:</code>循环来替换递归:</p>
<pre class="lang-py prettyprint-override"><code>def create_new_image():
while True:
new_image = {}
# For each trait category, select a random trait based on the weightings
new_image ["Plant"] = random.choices(plant, plant_weights)[0]
new_image ["Pot"] = random.choices(pot, pot_weights)[0]
new_image ["Face"] = random.choices(face, face_weights)[0]
if new_image not in all_images:
return new_image
</code></pre>