How to group array based on the same values

2024/11/19 2:20:18

Please, confused with array in python. I want to group array based on the same values.

Code:

enter image description here

id_disease = ['penyakit_tepung','hawar_daun']
for id_disease in id_disease:qres = acacia.query( """PREFIX tst: <http://www.semanticweb.org/aalviian/ontologies/2017/1/untitled-ontology-10#>SELECT ?disease ?patogenWHERE { ?disease tst:caused_by ?patogen . FILTER regex(str(?disease), "%s") .} """ % id_disease )for row in qres:for r in row:print(r.replace('http://www.semanticweb.org/aalviian/ontologies/2017/1/untitled-ontology-10#',''))print("\n")

Output:

penyakit_tepung
spaerotheca_sppenyakit_tepung
oidium_sppenyakit_tepung
erysiphe_sphawar_daun
cylindrocladium_sphawar_daun
kirramyces_sphawar_daun
phaeophleopspora_sp

Expected Array :

[['spaeerotheca_sp','oidium_sp','erysiphe_sp'].['cylindrocladium_sp','kirramyces_sp','phaeophleopspora_sp']]

Please, help me if you know how step to get it.

Answer

It should be

listoflists = []for row in qres:a_list = []for r in row:data = r.replace('http://www.semanticweb.org/aalviian/ontologies/2017/1/untitled-ontology-10#','')a_list.append(data)listoflists.append(a_list)print listoflists
https://en.xdnf.cn/q/120003.html

Related Q&A

latest video by youtube api

In order to learn this api I am trying to create a bot.one of the things this bot does is to first comment when a channel uploads a video.On some channels it works however on some channels it doesnt wo…

Function to switch between two frames in tkinter

Im looking through the code at passing-functions-parameters-tkinter-using-lambda, and needed a tad more functionality inside his class PageOne(tk.Frame). Instead of using lambda commands below (as he …

Get values from a tuple in a list in Python

x = Bookshop() x.orders = [ [1, ("5464", 4, 9.99), ("8274",18,12.99), ("9744", 9, 44.95)], [2, ("5464", 9, 9.99), ("9744", 9, 44.95)], [3, ("5464&…

Last Digit of the Sum of Fibonacci Numbers

I am trying to find the last digit of sum of Fibonacci Series. I calculate the sum as F(n+2) - 1. The below code is working fine but it is slow for large numbers (e.g 99999). How can I optimize this?n…

Django websites not loading

I have two Django websites on one server using Apache with mod_wsgi on Windows 10. For some reason the Django websites dont load, however, I have a normal website that does. Ive had it work in the past…

list manipulation and recursion

I have a mansory-grid in a pdf-page. The grid is choosen randomly, so i do not know how much upright cells or cross cells I have to fill. In my list I have all images that I want to proceed, each marke…

Getting TypeError: int object is not callable

Getting TypeError: int object is not callable. What am i doing wrong as i just want to add 10 to the z variableprint ("Hello World")x=int(input("Enter X")) y=int(input("Enter Y…

How to create a loop from 1-9 and from a-z?

I currently use:for i in range(1,10):print iWhich prints the digits 1 to 9. But I want to add a-z to the mix. How can I combine them?

Need Python to accept upper and lower case input

I want my Python code to accept both uppercase and lowercase input.Ive tried casefold, but with no luck. Any help?advice ="" while advice !=("Yes"):print("Would you like some…

What is [1] , in sock.getsockname()[1]? [duplicate]

This question already has answers here:How to access List elements(5 answers)Closed 7 years ago.I was going through socket programming in Python and I saw this: sock.getsockname()[1] Can anyone please …