跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[Python] Python 升序、查找高效的集合方案?

发表于
需要一个集合,要求:
1. 遍历时是升序
2. in 查找很高效

特点:
1. 初始化后,没遍历和 in 之外的其它操作,即初始化后不会更新
2. 初始化就是升序的
3. 大量的遍历和 in 操作
4. 集合内元素是唯一的

最早用的是 list ,缺点:in 低效
现在用 set ,缺点:遍历出来不是升序。刚刚发现非升序,在一些地方会有问题

希望方案很简单,最好是用标准库解决

一个可能的解决方案:bisect 。但用起来有点小麻烦
一个可能的解决方案,自己 new 一个类型,包装 list 和 set ,遍历用 list ,in 用 set

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.