I am trying to do something like the following in python, but i am getting an invalid syntax error:
network_n = 192.168.38
octate_n = network_n.split(".")
if (len(o) [for o in octate_n]) == 3:
But when i am run it, i get:
if (len(o) [for o in octate_n]) == 3:
^
SyntaxError: invalid syntax
My problem is with the if statement, what is wrong there ?
I admit that i have a rough idea about the difference between the () and the [] in the if statement, so i would be glad that you give me a short explanation about it.
Use
all:About your seconds question,
[o for o in octate_n]creates a list that consists of all items inoctate_n(this is called a list comprehension), while(o for o in octate_n)creates a generator that will yield all the items ofoctate_n(this is called a generator expression).