문제

I just started with haskell and im wondering if there is a easy way to match the letters between 2 string and output them.

like:

iced and liked will return i,e,d

Thank you!

도움이 되었습니까?

해결책

Use Data.Set.intersection:

 import qualified Data.Set as S

 sharedLetters str1 str2 = S.toList $ S.intersection (S.fromList str1) (S.fromList str2)

EDIT: As @jozefg pointed out, there is a function in Data.List which does the same for lists:

 > import Data.List (intersect)
 > intersect "liked" "iced"
 "ied"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top