python实现输入一个列表
@耿鹏6138:Python怎样才能input一个list -
郁鲍15134312945…… >>> li ['a', 'b', 'mpilgrim', 'z', 'example']>>> li.append("new")>>> li ['a', 'b', 'mpilgrim', 'z', 'example', 'new']>>> li.insert(2, "new")>>> li ['a', 'b', 'new', 'mpilgrim', 'z', 'example', 'new']>>> li.extend(["two", "elements"]) >>> li ['a', 'b', 'new', 'mpilgrim', 'z', 'example', 'new', 'two', 'elements']
@耿鹏6138:python中输入一个list -
郁鲍15134312945…… list = ['c','b','a'....] print(list); #输出
@耿鹏6138:用python设计一函数,实现输入一个列表,求出列表的总和 -
郁鲍15134312945…… def list_add(a): c = 0 for i in range(len(a)): c = c + a[i] return c
@耿鹏6138:python编写一函数.输入列表,其中的数据均为数值型.例如:[23,6, - 4, - 9.8,99, - 6].将其中的所有负数放? -
郁鲍15134312945…… 把判断函数放进filter 里 然后就可以得到两个列表 然后拼在一起就行了
@耿鹏6138:用python编写脚本程序,实现用户输入3个整数,放入列表,并输出最小值 -
郁鲍15134312945…… list1 = input("请输入3个以空格为间隔的整数:").split() """以空格进行分割,删去字符串中的空格,剩下的元素以列表形式返回""" print("最小值为:",min(list1)) #利用内置函数min()返回最小值
@耿鹏6138:python 列表操作 -
郁鲍15134312945…… a_list=[ ['a','b','c'], ['d','e','f'], ['g','h','i'], ['j','k','l'] ] b_list = [] for i in a_list: for x in i: b_list.append(x) 或者用列表解析 b_list += [x for i in a_list for x in i]
@耿鹏6138:python 创建一个列表,依次存放每个月对应的天数,假设2月份的天数为28天,根据用户输入的月份? -
郁鲍15134312945…… l = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] while True:a = eval(input('请输入月份(输入0退出):')) if a == 0: exit()try: print('{}月共有{}天'.format(a, l[a-1]))except: print('你的输入有误!')
@耿鹏6138:输入一个列表,将列表中最大值和第一个值进行交换.用python -
郁鲍15134312945…… >>> c=[-10,-5,0,5,3,10,15,-20,25] >>> a=c.index(max(c)) >>> b=max(c) >>> c[a]=c[0] >>> c[0]=b >>> print c [25, -5, 0, 5, 3, 10, 15, -20, -10]
@耿鹏6138:python 怎么传入列表参数 -
郁鲍15134312945…… 那就在调用参数的时候,给它赋值一个列表 def test(ls): print "this is a list"a = [1,2,3]#调用test(a)
@耿鹏6138:python程序输入一个包含3个整数的list,将它们从小到大赋给一个列表,怎么写程序? -
郁鲍15134312945…… 如果是a="[1,2,3,4,5,6,7]",那么可以替换掉方括号,然后用split方法拆分字串 a="[1,2,3,4,5,6,7]" a=a.replace('[', '') a=a.replace(']', '') a=map(lambda i: int(i), a.split(','))
郁鲍15134312945…… >>> li ['a', 'b', 'mpilgrim', 'z', 'example']>>> li.append("new")>>> li ['a', 'b', 'mpilgrim', 'z', 'example', 'new']>>> li.insert(2, "new")>>> li ['a', 'b', 'new', 'mpilgrim', 'z', 'example', 'new']>>> li.extend(["two", "elements"]) >>> li ['a', 'b', 'new', 'mpilgrim', 'z', 'example', 'new', 'two', 'elements']
@耿鹏6138:python中输入一个list -
郁鲍15134312945…… list = ['c','b','a'....] print(list); #输出
@耿鹏6138:用python设计一函数,实现输入一个列表,求出列表的总和 -
郁鲍15134312945…… def list_add(a): c = 0 for i in range(len(a)): c = c + a[i] return c
@耿鹏6138:python编写一函数.输入列表,其中的数据均为数值型.例如:[23,6, - 4, - 9.8,99, - 6].将其中的所有负数放? -
郁鲍15134312945…… 把判断函数放进filter 里 然后就可以得到两个列表 然后拼在一起就行了
@耿鹏6138:用python编写脚本程序,实现用户输入3个整数,放入列表,并输出最小值 -
郁鲍15134312945…… list1 = input("请输入3个以空格为间隔的整数:").split() """以空格进行分割,删去字符串中的空格,剩下的元素以列表形式返回""" print("最小值为:",min(list1)) #利用内置函数min()返回最小值
@耿鹏6138:python 列表操作 -
郁鲍15134312945…… a_list=[ ['a','b','c'], ['d','e','f'], ['g','h','i'], ['j','k','l'] ] b_list = [] for i in a_list: for x in i: b_list.append(x) 或者用列表解析 b_list += [x for i in a_list for x in i]
@耿鹏6138:python 创建一个列表,依次存放每个月对应的天数,假设2月份的天数为28天,根据用户输入的月份? -
郁鲍15134312945…… l = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] while True:a = eval(input('请输入月份(输入0退出):')) if a == 0: exit()try: print('{}月共有{}天'.format(a, l[a-1]))except: print('你的输入有误!')
@耿鹏6138:输入一个列表,将列表中最大值和第一个值进行交换.用python -
郁鲍15134312945…… >>> c=[-10,-5,0,5,3,10,15,-20,25] >>> a=c.index(max(c)) >>> b=max(c) >>> c[a]=c[0] >>> c[0]=b >>> print c [25, -5, 0, 5, 3, 10, 15, -20, -10]
@耿鹏6138:python 怎么传入列表参数 -
郁鲍15134312945…… 那就在调用参数的时候,给它赋值一个列表 def test(ls): print "this is a list"a = [1,2,3]#调用test(a)
@耿鹏6138:python程序输入一个包含3个整数的list,将它们从小到大赋给一个列表,怎么写程序? -
郁鲍15134312945…… 如果是a="[1,2,3,4,5,6,7]",那么可以替换掉方括号,然后用split方法拆分字串 a="[1,2,3,4,5,6,7]" a=a.replace('[', '') a=a.replace(']', '') a=map(lambda i: int(i), a.split(','))