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.
私は助けが必要です:
リストを入力として受け取り、特定の文字列のカウントを返す関数を書きたいと思います。
関数入力が x=[a,a,b,c]関数である場合は、リターンが必要です2(aこのリストでは は 2 回)。
x=[a,a,b,c]
2
a
>>> def F(seq, string): return seq.count(string) >>> F(['a','a','b','c'], 'a') 2
に相当:
def F(seq, string): n = 0 for x in seq: if x == string: n += 1 return n