a = "Show me the money"
b = input("입력하셈"\n")
print(a.count(b))
print(a.find(b))
제가 만약에 e를 쳤으면
e는 총 3개 있고 6번째랑 10번째에 위치해있다고 그렇게 뜨게하고싶은데 어떻게 하는지 모르겠음
예를 들어서 "e is at the 5th location. e is at the 12th location. The string has 2 of e character."
a = "Show me the money"
b = input("입력하셈"\n")
print(a.count(b))
print(a.find(b))
제가 만약에 e를 쳤으면
e는 총 3개 있고 6번째랑 10번째에 위치해있다고 그렇게 뜨게하고싶은데 어떻게 하는지 모르겠음
예를 들어서 "e is at the 5th location. e is at the 12th location. The string has 2 of e character."
length = a.split('e').length-1
꼭 스플릿 써야할필요는 없을듯
이건 내장함수로 안되고 너가 로직을 추가적으로 짜야함 ㄱㄷ
일단 개수 찾는건 count가 맞음
find 부분이 문제인데 가장 좋은 방법은 루프를 돌면서 다 찾는거임
t = 0 (a.split('e')).each do |i| puts (i.length+1+t).to_s + '갯수' t += i.length+1 end
맨위가 갯수고
아니 파이썬 질문글에 왜 루비를 달아요
밑에가 위치인데 모르고 갯수라고 적음
이개 루비의 우아함이다
ㅋㅋㅋㅋㅋ 닉값
페이스트빈 곧 갑니다
함수형언어로 foldLeft 합시다잉
루비가 서양에서만 나왔어도 코딩언어 통일됬따
https://pastebin.com/ERBjQ8PK
결과:
https://pastebin.com/nUGMLgJn
print(' '.join('%s is at the %sth location.' % (b, i) for i, c in enumerate(a) if c==b), 'The string has %s of %s character.' % (a.count(b), b)) - dc App