Python: if arrived to end of list -
The program I wrote for my assignment is: Tara 20080601, 'Pala19991231', 'Melo19601023'] second = ['Pala', 'Kara', 'Tara' The only problem is this That the teacher wants me to add / remove elements: I've written, he should take me OK right output, but it 'back', not lst1. So here's the solution that I was thinking (sorry for the pseudo code ..): If the codes in ccsc: lst1 + = [cccc, int (dd), int (mm) ) If the CCCC is not in the cod: lst1 + = [cccc + yyyy + mm + dd] If at the end of LST: Replace with lst1 P> < P> return lst So when the program has checked all the elements of LST, then something like this must be done Is this possible? How can I do this? Why do not you make a copy of
Def code (list, cod): LST: [0: 4] for element in element = element = yyyy = element [4: 8] mm = element [8:10] dd = element [10:12] If in cccc cods : Lst1 + = [cccc, int (dd), int (mm), int (yyyy)] if not in cccc codes: lst1 + = [cccc + yyyy + mm + dd] return lst1 first = ['cara20130716', ' Print code (first, second)
lst [:] = [] Lst.extend.lst1
lst? Code> In the first place, then attach new elements to the original elements? Maybe what you are trying to achieve, I do not get enough:
DIF codes (list, cod): lst1 = lst [:] lst [:] = [] For element in lst1: cccc = element [0: 4] yyyy = element [4: 8] mm = element [8:10] dd = element [10:12] If the CCC is in the codes: lst + = [cccc, Int (dd), int (mam), int (ya)] and: list + = [cccc + ya + mm + dd] returns LST first = ['kara 20130716', 'star 20080601', 'left 199 61231', 'Mailo1960103'] second = ['PALA', 'CARA', 'TARA'] print code (first, second)
Comments
Post a Comment