p=[1,2,3,4,5,6] while True: for i in p: if i==4: p=[] f=[9,8,7] p.extend(f) break print i£¬',', p.remove(i)
if not p: break #expect output is:1,2,3,9,8,7,
¸ßÊÖ°ïÎÒ¿´¿´£¬ÎªÊ²Ã´Îҵò»µ½ÎÒÏëÒªµÄ½á¹ûÄØ,ÓÐʲô·½·¨¿ÉÒԵõ½ÎÒÏëÒªµÄ½á¹ûÂð for i in p:Ó¦¸ÃÒª¼«Á¦±ÜÃâÈ¥¸Ä±äp¡£whileÀïËæ±ãÆð¸öÕûÊýµ±listϱêÀ´·ÃÎÊÔªËØ£¬È»ºóÑ»·µÝÔöÕâ¸öÕûÊý... for i in p: ---> iÊÇÁбípµÄÔªËØ p.remove(i) --->Õâ¸öiÊÇÁбípµÄË÷Òý