Hello, Programming/Python newb here looking for some help with arrays. I am trying to write a parsing program that takes a comma delimited csv file, compares entries, and outputs the comparisons in a particular format. The csv file has two columns. Col [0] contains article identifiers, col[1] contains assigned keywords. ![]() Feb 10, 2017 kasir sederhana; Python. Bisa digunkan untuk membuat program python. Sobat harus punya dulu software python di pc sobat. Program ini adalah program kasir sederhana. Sebagaimana kasir biasanya maka pada layar akan. Coba pake ini Software Aplikasi toko dan Kasir POS. It looks something like this: 3, antibiotics 3, resistance 3, mortality I wrote the following code, which compares the entry in row i, col 0, with the entry in row i+1, col 0. If the article id's are equal, then I need to print out the two keywords on the same line. The error is in this line print (edgelist1 [1],edgelist1[nextrow][1]) when you get to the last record, nextrow points beyond the end, so you want to use for i in range (0,listmax-1): since there is nothing to compare the last record to. Alternatively, you can use for i in range (1, listmax): and compare this record to the previous record. Also you want to be sure that the records are in numerical order, otherwise sort them first. Second, you do not need the while loop, as the for loop goes through all of the records, and you could get duplicate output, one from the while loop, and one from the for loop. You can then print the index value from the for loop which is also the record number (or index+1 if you want the first record to be one instead of zero). Finally, it is bad practice to use 'i', 'l', or 'o' as single digit variable names as they can look like numbers. For x in range (0,listmax-1): nextrow=x+1 if edgelist1[x][0]==edgelist1[nextrow][0]: ## how this print statement should be formated depends on ## the Python version you are using print ('rec #%d%s%s'% (x+1, edgelist1[x][1], edgelist1[nextrow][1])). I tried the code, and there was a slight problem with it - it did not extract all the possible combinations for any given article, just the combinations of the first keyword and subsequent keywords. Your original code will give results until it finds a record that does not match, and not necessarily all of the matches. It is also redundant. You print ANTIMICROBIAL RESISTANCE CARRIAGE ANTIMICROBIAL RESISTANCE EXPERIENCE because they are all equal, then you print CARRIAGE EXPERIENCE which is a duplication of the first printing. I don't know if this is what you want or not. The problem with the original code is that it has to process the file many, many times. Download film itazura na kiss sub indo 21. That is, each record is compared with every other record (potentially). If the program doesn't take too long to run, then this is OK. Otherwise you want to process the file in one pass. The best way to do this is probably to place the records in a dictionary of lists, where the key is the number, pointing to a list of lists, each list containing whatever you want, the description and the record number perhaps. You then extract any key that has more than one entry. Post the first 10 or so records if you want any more help, as the code snippet that I posted should work for the 3 record examples in your first post. If you want to use the while() statement then you must test for end of file while (nextrow.
0 Комментарии
Оставить ответ. |
АвторНапишите что-нибудь о себе. Не надо ничего особенного, просто общие данные. АрхивыКатегории |