10 класс, задание 4,5. PYTHON

Приложения:

Ответы

Ответ дал: Koljisto
0

4)

W = "str" # find

ST = "str str str gfdstr strstr" # =

V = "nope" # replace

pos = -1

while True:

   pos = ST.find(W, pos + 1)

   if pos == -1:

       break

   ST = ST.replace(ST[pos:pos+len(W)], V)

print(ST)

5)

str1 = "abcdefg" # alphabet and first str

str2 = "defgddsdfgweasdqa" # second str for search and counter in loop of all occurrences

list1 = []

list2 = []

for i in range(0,len(str1)):

   if str2.count(str1[i]) == 0:

       continue

   else:

       list1.append(str2.count(str1[i]))

       list2.append(str1[i])

for i in list2:

   print(i, end = " ")

print()

for i in list1:

   print(i, end = " ")

Приложения:
Вас заинтересует