gpt4 book ai didi

java - 解释Python并转换为Java

转载 作者:行者123 更新时间:2023-12-01 06:55:17 27 4
gpt4 key购买 nike

Darius Bacon's code ,第11、12行有如下代码:

prefixes = set(word[:i] for word in words for i in range(2, len(word)+1))

我正在尝试将他的程序翻译成 Java,但我在这方面遇到了困难。

这是做什么的?

最佳答案

扩展列表理解:

prefixes = set()
for word in words:
for i in range(2, len(word)+1)
prefixes.add(word[:i])

word[:i]word 直至但不包括索引 i

关于java - 解释Python并转换为Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13333676/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com