Ristructer
Ristructer
import collections
str1 = 'sayaadalahpelajarupsi'
d = collections.defaultdict(int)
for c in str1:
d[c] += 1
if d[c] > 1:
import textwrap
sample_text = '''
as C++ or Java.
'''
print()
print(textwrap.fill(sample_text, width=70))
print()
4. Write a Python program to add 'ing' at the end of a given string (length should be at least 3). If the
given string already ends with 'ing' then add 'ly' instead. If the string length of the given string is less
than 3, leave it unchanged.
def add_string(str1):
length = len(str1)
if length > 2:
if str1[-3:] == 'ing':
str1 += 'ly'
else:
str1 += 'ing'
return str1
print(add_string('ab'))
print(add_string('abc'))
print(add_string('string'))
5. Write a Python program to remove the characters which have odd index values of a given string.
def odd_values_string(str):
result = ""
for i in range(len(str)):
if i % 2 == 0:
return result
print(odd_values_string('abcdef'))
print(odd_values_string('python'))