Avatar ·

How to check if a slice in Go contains a specific element? Analog of contains() for slice

Hello everyone! I just started learning Go after Python and encountered an unexpected problem. In Python, there is a convenient `in` operator that allows you to check if an element is in a list: `if element in my_list:`. In Go, I work with slices and often need to check if a slice contains a specific string or number. For example, I have a slice of strings: ```go fruits := []string{"apple", "banana", "cherry"} ``` I want to check if it contains "banana". In the Go standard library, I didn't find a built-in method like `contains()` for slices. I tried writing a loop myself, but it seems like too much code for such a simple operation. Maybe there is some standard way or idiomatic solution in Go? Or do I need to write my own function every time? Thanks in advance for your help.