在我的python项目中,我需要列出字符串中特定字符的所有匹配项,例如:A -> ABHAXA -> [0,3,5]
我知道像这样的解决方案可行:
indices = [i for i, x in enumerate(my_list) if x == "whatever"]
但问题是,为了满足这个项目的要求,我不能以任何方式使用for循环。有没有一种很好的方法可以使用filter,map等来做到这一点?
谢谢!
答案 0 :(得分:2)
这个怎么样:
class Account
{
private decimal _amount;
private decimal _balance;
public decimal Balance
{
get { return _balance; }
private set { _balance = value; }
}
public Account(decimal pBalance)
{
this.Balance = pBalance;
}
public decimal Amount
{
get { return _amount; }
set
{
if (value < 0)
{
throw new ArgumentException("Please enter an amount greater than 0");
}
else
{
_amount = value;
}
}
}
public decimal Deposit()
{
_balance = _balance + _amount;
return _balance;
}
public decimal Withdrawl()
{
if (_balance - _amount < 0)
{
throw new ArgumentException("Withdrawing " + _amount.ToString("C") + " would leave you overdrawn!");
}
_balance = _balance - _amount;
return _balance;
}
}