result = 0
for each in list1:
result += len(each) if isinstance(each,str) else each
return result def sum(mylist):
sum=0
for i in mylist:
if isinstance(i,str):
i=len(i)
sum=sum+i
return sum
sum()
a=
def b(a):
c=a+"b"
def sum1(list1):
result =0
for item in list1:
ifisinstance(item,list1):
number =len(item)
else:
number=item
result+=number
return result
def sum1(lst):
newList = []
for i in lst:
if isinstance(i, str):
newList.append(len(i))
else:
newList.append(i)
return sum(newList)
a =
b =
c =
d = ['12321','asdewdew']
print(sum1(a))
print(sum1(b))
print(sum1(c))
print(sum1(d))
def calc(L):
return sum() def sum1(lis):
result = 0
for i in lis:
if isinstance(i, str):
i = len(i)
result += i
return result {:5_91:} def sum1(list):
from functools import reduce
return reduce(lambda x,y:x+(len(y) if isinstance(y, str)else y),list) def sum1(list1):
return sum()
print(sum1()) def sum_all(list_):
result = 0
for each in list_:
if isinstance(each, str):
result += len(each)
elif isinstance(each, (int, float)):
result += each
else:
pass
return result 1
a =
def Sum(lis):
b = []
for i in a:
if isinstance(i,(int,float)):
b.append(i)
else:
b.append(len(i))
return sum(b)
Sum(a) def sum1(list1):
num = 0
if type(list1) != list:
print("请输入一个列表")
else:
length = len(list1)
for i in range(length):
if type(list1) == str:
num += len(list1)
else:
num += list1
return num
学习 for i in sum1(list1):
页:
1
[2]