s = "hdjdopanndfyazgbz"
list01 = list(s)
for i in range(len(list01)-1):
for j in range(len(list01)-1-i):
if list01[j] > list01[j+1]:
list01[j], list01[j+1] > list01[j+1], list01[j]
print(list01)
str = ''.join(list01)
print(str)
list02 = ['dii', 'eowojsns', 'ueueu', 'iwjsjdjn', 'a', 'dujejenebisis']
for i in range(len(list02)-1):
for j in range(len(list02)-1-i):
if len(list02[j]) > len(list02[j+1]):
list02[j], list02[j+1] = list02[j+1], list02[j]
print(list02)
- 随机生成0~100之间的10个数,从小到大冒泡排序
import random
number = range(0, 101)
numbers = random.sample(number, 10)
for i in range(len(numbers)-1):
for j in range(len(numbers)-1-i):
if numbers[j] > numbers[j+1]:
numbers[j], numbers[j+1] = numbers[j+1], numbers[j]
print(numbers)
L = {'李华': 98, '张三': 345, '李四': 659, '王五': 110, '赵六': 359, '甲': 160, '乙': 368, '丙': 580}
ll = list(L.items())
for i in range(len(ll)-1):
for j in range(len(ll)-1-i):
if ll[j][-1] > ll[j+1][-1]:
ll[j], ll[j+1] = ll[j+1], ll[j]
print(ll)
LL = dict(ll)
print(LL)
nums = [1, 3, 5, 7, 8, 9, 5, 4, 3, 2, 4]
for i in range(len(nums)-1):
for j in range(len(nums)-1-i):
if nums[j] > nums[j+1]:
nums[j], nums[j+1] = nums[j+1], nums[j]
print(nums)
input_str = list(input("请输入:"))
for i in range(len(input_str)-1):
for j in range(len(input_str)-1-i):
if input_str[j] > input_str[j+1]:
input_str[j], input_str[j+1] = input_str[j+1], input_str[j]
print(input_str)
list1 = [("Sadasfa", 'sdas', 'sdsa2f', 'ss', 'a', 'ffafafsf'), 22, 321, 1, ("aaeqweqw", 'dssqa', 'saew1', 'sda', '2sdgfd'), {'a': 232, 'kbd': 1, 'ww': 221, 'kk': 29, 'kp': {'c': 11, 'pp': 1}}]