1. 请用代码实现:利用下划线将列表的每一个元素拼接成字符串,li = ['alex', 'eric','rain']
li = ['alex', 'eric', 'rain']
str_li = "_".join(li)
print(str_li)
alex_eric_rain
2.查找列表中元素,移除每个元素的空格,并查找以a或A开头并且以c结尾的所有元素
import re
li = ["alec", " aric", "Alex", "Tony", "rain"]
tu = ("alec", " aric", "Alex", "Tony", "rain")
dic = {'k1': "alex", 'k2': ' aric', "k3": "Alex", "k4": "Tony"}
my_list = []
for i in li: #tu同li
print(i.strip())
result = re.findall('^[aA].*c$',i.strip())
result1 = "".join(result)
if result1 != "":
my_list.append(result1)
print(my_list)
for i in dic:
print(dic[i].strip())
result = re.findall('^[aA].*c$',dic[i].strip())
result1 = "".join(result)
if result1 != "":
my_list.append(result1)
print(my_list)
3. 写代码,有如下列表,按照要求实现每一个功能
li = ['alex', 'eric', 'rain']
计算列表长度并输出
print(len(li))
列表中追加元素“seven”,并输出添加后的列表