You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将表格ID列中的随机编号按“From - To”格式整理展示?

Organizing Scattered IDs into Range Format

Hey there, let's get those messy IDs sorted into the clean range format you're looking for. First up, here's the final formatted output you requested:

8v12020, From 8v12023 To 8v12025, 8v12027, From 8v12029 To 8v12030

How to replicate this manually:

  • Step 1: Sort by numeric suffix
    Pull the number part after 8v from each ID, then sort them in ascending order:
    12020, 12023, 12024, 12025, 12027, 12029, 12030
  • Step 2: Group consecutive sequences
    Spot IDs where the numeric suffix increases by exactly 1 each time, and format ranges accordingly:
    • Single standalone ID: 8v12020
    • Consecutive range (23→24→25): From 8v12023 To 8v12025
    • Single standalone ID: 8v12027
    • Consecutive range (29→30): From 8v12029 To 8v12030
  • Step 3: Combine all parts
    String the single IDs and formatted ranges together with commas to get the final result.

For bulk processing (Python script):

If you've got a huge list of IDs and want to automate this, here's a quick, reusable script:

# Your list of IDs
ids = ["8v12027", "8v12025", "8v12024", "8v12029", "8v12023", "8v12030", "8v12020"]

# Sort IDs based on their numeric suffix
sorted_ids = sorted(ids, key=lambda x: int(x[2:]))

result = []
current_group = [sorted_ids[0]]

for id in sorted_ids[1:]:
    prev_num = int(current_group[-1][2:])
    curr_num = int(id[2:])
    # Check if current ID is consecutive to the last in the group
    if curr_num == prev_num + 1:
        current_group.append(id)
    else:
        # Add group to result (format as range if multiple entries)
        if len(current_group) > 1:
            result.append(f"From {current_group[0]} To {current_group[-1]}")
        else:
            result.append(current_group[0])
        current_group = [id]

# Add the final remaining group
if len(current_group) > 1:
    result.append(f"From {current_group[0]} To {current_group[-1]}")
else:
    result.append(current_group[0])

# Generate the final formatted string
final_output = ", ".join(result)
print(final_output)

内容的提问来源于stack exchange,提问作者vikrant gawali

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 09:56:45