index()
will just give the first occurrence of an item in a list. Is there a neat trick which returns all indices in a list?
Answer
You can use a list comprehension:
indices = [i for i, x in enumerate(my_list) if x == "whatever"]
index()
will just give the first occurrence of an item in a list. Is there a neat trick which returns all indices in a list?
Answer
You can use a list comprehension:
indices = [i for i, x in enumerate(my_list) if x == "whatever"]
I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...
No comments:
Post a Comment