Case study of python list
This article mainly explains "python list case analysis". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let Xiaobian take you to learn "python list case analysis"!
Here are the lists:
Task 1,"Y2K Bug" Here I come Function enumerate
The enumerate() function is used to assemble a traversable data object (such as a list, tuple, or string) into an index sequence, listing both the data and the data subscript, typically used in a for loop.
year=[82,89,88,86,85,00,99]print ('original list', year)for index,value in enumerate(year): print(index,value)
year=[82,89,88,86,85,00,99]print ('original list', year)for index,value in enumerate(year): #print(index,value) if str(value)!= '0': year[index]=int('19'+str(value)) else: year[index]=int ('200 '+str(value))print ('modified list:', year)
Original list: [82, 89, 88, 86, 85, 0, 99]
Modified list: [1982, 1989, 1988, 1986, 1985, 2000, 1999]
year=[82,89,88,86,85,00,99]print ('original list:', year)for index,value in enumerate(year): #print(index,value) if str(value)!= '0': year[index]=int('19'+str(value)) else: year[index]=int ('200 '+str(value))print ('list after modification:',year)#sort of list year.sort()print ('list after sorting:',year)
Original list: [82, 89, 88, 86, 85, 0, 99]
Modified list: [1982, 1989, 1988, 1986, 1985, 2000, 1999]
The sorted list is: [1982, 1985, 1986, 1988, 1989, 1999, 2000]
Task 2. Jingdong Shopping Process Warehousing Operation lst=[]for i in range(0,5): goods=input ('Please input the commodity preparation and commodity name to enter the receipt of commodities. Only one commodity can be input at a time:\n') lst.append(goods)for item in lst: print(item)
Please enter the commodity preparation and commodity name to enter the commodity receipt. You can only enter one commodity at a time:
1001 mobile phone
Please enter the commodity preparation and commodity name to enter the commodity receipt. You can only enter one commodity at a time:
1002 watch
Please enter the commodity preparation and commodity name to enter the commodity receipt. You can only enter one commodity at a time:
1003 portable watch
Please enter the commodity preparation and commodity name to enter the commodity receipt. You can only enter one commodity at a time:
1004 Laptop
Please enter the commodity preparation and commodity name to enter the commodity receipt. You can only enter one commodity at a time:
1005 flashlight
1001 mobile phone
1002 watch
1003 portable watch
1004 Laptop
1005 flashlight
lst=[]for i in range(0,5): goods=input ('Please input the commodity preparation and commodity name to enter the receipt of commodities. Only one commodity can be input at a time:\n') lst.append(goods)for item in lst: print(item)cart=[]while True: num=input ('Please enter the item number you want to buy:') for item in lst: if item.find(num)!=- 1: cart.append(item) break#exit for if num=='q': break#exit while loop print ('The items selected in your cart are:')''for m in cart: print(m)'''for i in range(len(cart)-1,-1,-1): print(cart[i])
At this point, I believe everyone has a deeper understanding of "python list case analysis", so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!