Skip to content

Latest commit

 

History

History
48 lines (26 loc) · 829 Bytes

A_Needle_in_the_Haystack.md

File metadata and controls

48 lines (26 loc) · 829 Bytes

CodeWars Python Solutions


A Needle in the Haystack

Definition

Can you find the needle in the haystack?

Write a function findNeedle() that takes an array full of junk but containing one "needle"

After your function finds the needle it should return a message (as a string) that says:

"found the needle at position " plus the index it found the needle, so:

find_needle(['hay', 'junk', 'hay', 'hay', 'moreJunk', 'needle', 'randomJunk'])

should return "found the needle at position 5"


Given Code

def find_needle(haystack):
    pass

Solution

def find_needle(haystack):
    return "found the needle at position {}".format(haystack.index("needle"))

See on CodeWars.com