1.请用代码实现:利用下划线将列表的每一个元素拼接成字符串,li = ["alex","eric","rain"]
l = []
tag = "_"
for i in li:
l.append(i)
k = tag.join(i)
print(k)
2.查找列表中元素,移除每个元素的空格,并查找以a或A开头并且以c结尾的所有元素。
(1)li =["alec","aric","Alex","Tony","rain"]
(2)tu = ("alec","aric","Alex","Tony","rain")
(3)dic = {"K1":"alex","K2":" aric","K3":"Alex","K4":"Tony"}
(1)for i in li:
if i.startswith("a") or i.startswith("A"):
if i.endswith("c"):
print(i)
(2) for i in tu:
if i.startswith("a") or i.starswith("A"):
if i.endswith("c"):
print(i)
(3) for i in dic:
if dic[i].startswith("a") or dic[i].startswith("A"):
if dic[i].endswith("c"):
print(i)
3.li = ['alex','eric','rain']
*计算列表长度并输出
print(len(li))
*列表中追加元素"seven",并输出添加后的列表
li.append("seven")
print(li)
*请在列表的第一个位置插入元素”tony",并输出添加后的列表
li.insert(0,"Tony")
print(li)
*请把列表反转,并输出
li.reserve()
print(li)