I need to know if a variable in Python is a string(name) or a number. I want to check out the degree of graphs, however I need to know if "i" iterator, is a number inside of the string or a name inside of the string, showing the degree of graphs at the end.
Is there something wrong in this code?
import csv, sys
import networkx as nx
def ministro_lei():
stf = csv.reader(open('resultset.csv', 'rb'), delimiter=',', quotechar='|')
eds = [(i[0],i[1],i[2]) for i in stf]
G = nx.DiGraph(nome='ministro_lei')
G.add_weighted_edges_from(eds)
for i in G.degree():
if isinstance(i,str):
print (" This is a name:", i)
elif isinstance(i, int):
print ("This is a number: ", i)
else:
raise ValueError
return G, eds
ministro_lei = ()
Here lies some examples of outs:
"MIN. OCTAVIO GALLOTTI",53,109
"MIN. SYDNEY SANCHES",13,109
"MIN. JOAQUIM BARBOSA",101,108
Please any help? Thanks
returnat the end of the methodministro_leireturns two variables. However, there are two morereturn (i)lines within the loops, that return single variables. This structure will never pass past the first iteration of the for-loop. Is this what you want?