Quick actions

cmd+k|ctrl+k

Navigation

Languages

quangtranhong - pyfml - Exercise 3. Ext 1

Snippet info

Language

Python

Visibility

public

Author

quangtranhong

Created

2016-09-24T04:41:18Z

Updated

2016-09-24T05:53:10Z

# Bài 1:
# ------
# a) Viết 1 chương trình tìm kí tự xuất hiện nhiều nhất trong 1 chuỗi
# b) Viết 1 chương trình đếm số tần xuất hiện của các ki tự trong 1 chuỗi
# Ví dụ::
# 'toi la aia' -->> t: 1, o: 1, i: 2, l: 1, a: 3

list_char = []
list_dict = []
input = "Python is a programming language that lets you work more quickly and integrate your systems more effectively."
string = ''

for i in input:
	if i not in list_char and i != ' ':
		list_char.append(i)
# print(list_char)

for i in list_char:
	count = 0
	list_temp = []
	for j in input:
		if i == j:
			count += 1
	list_temp.append(i)
	list_temp.append(count)
	list_dict.append(list_temp)

max = list_dict[0][1]

for i in list_dict:
	if max < i[1]:
		max = i[1]

for i in list_dict:
	if i[1] == max:
		print('Ky tu co so lan xuat hien nhieu nhat:', i)

for i in list_dict:
	# string + i[0] + ': ' + str(i[1]) + ', '
	string = string + '(\'' + i[0] + '\': ' + str(i[1]) + '), '
	
print('List cac ky tu va so lan xuat hien: ' + string[:len(string)-2])
INFO