python - print([[i+j for i in "abc"] for j in "def"]) -
i'm new python.
i stumped upon 1 of comprehension
print([[i+j in "abc"] j in "def"])
could please me convert comprehension in loop?
i'm not getting desired result loop:
list = [] list2 = [] j in 'def': in 'abc': list.append(i+j) list2 = list print (list)
the above try loop. i' missing something. below should desired result in loop want.
([[‘ad’, ‘bd’, ‘cd’], [‘ae’, ‘be’, ‘ce’], [‘af’, ‘bf’, ‘cf’]])
which believe matrice.
thanks in advance.
the easiest thing unravel comprehension take 1 comprehension @ time , write that loop. so:
[[i+j in "abc"] j in "def"]
becomes:
outer_list = [] j in "def": outer_list.append([i + j in "abc"])
alright, cool. we've gotten rid of outer comprehension can unravel inner comprehension next:
outer_list = [] j in "def": inner_list = [] in "abc": inner_list.append(i + j) outer_list.append(inner_list)
Comments
Post a Comment