ダリウスベーコンのコードの11行目と12行目には、次のコードがあります。
prefixes = set(word[:i] for word in words for i in range(2, len(word)+1))
私は彼のプログラムをJavaに翻訳しようとしていますが、これに問題があります。
これは何をしますか?
ダリウスベーコンのコードの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でこれを試してください
Set<String> prefixes = new HashSet<String>();
for(String word:words){
for(int i=1;i<word.length;i++){
prefixes.add(word.substring(0,i));
}
}