Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
私はこれを持っています:
word = 'abcd'
そして、私はこれが欲しい:
do_something(word) >>['a', 'ab', 'abc', 'abcd']
word = 'abcd' def do_something(word): return [word[:x + 1] for x in xrange(len(word))] print do_something(word)
結果:
['a', 'ab', 'abc', 'abcd']
単純:
[word[:i] for i in xrange(len(word))]