English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
When coding, sometimes you need to assign values according to comparison size:
import random seq = [random.randint(0, 1000) for _ in range(100) #Method1: xmax, xmin = max(seq), min(seq) #Method2: xmax, *_, xmin = sorted(seq)
From the above, it is not easy to see the method2Taking advantage of the advantage, but we often use it to compare the size of two numbers and select:
dx, dy = random.sample(seq, 2) #Method1: dx, dy = min(dx, dy), max(dx, dy) #Method2: dx, dy = sorted((dx, dy))
It can still save a few letters.
This is the full content shared by the editor, hoping to provide a reference for everyone, and also hope that everyone will support the呐喊 tutorial more.
Statement: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously, and this website does not own the copyright, has not been manually edited, and does not assume relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#w3Please replace # with @ when sending an email to report, and provide relevant evidence. Once verified, this site will immediately delete the content suspected of infringement.