cbiqih
发表于 2017-8-27 19:21:46
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Created by lightwave on 2017/8/27
def sort_func(x):
ord_x = ord(x)
return ord_x if ord_x <= ord('Z') else ord(x.upper()) + 0.1
content = input('请输入内容:')
new_content = ''.join(sorted(content, key=sort_func))
print("排序后内容:", new_content)
张大象
发表于 2017-9-18 15:35:38
a = 'easqWAwaeq'
print(a)
print(''.join(sorted(a, key=lambda x:ord(x.lower())*2+x.islower())))
gausser
发表于 2017-9-21 22:15:40
# all the char change to lowercase, then sort the string
def SortString(string):
LowerString = string.lower()
StrList = list(LowerString)
StrList.sort()
LowerString = "".join(StrList)
return LowerString
# Find the uppercase in the original string;
# Conversion the lowercase to uppercase in the new string if it is uppercase in the original string
def MainFunction(string):
# sort the original string
NewString = SortString(string)
for i in range(len(string)):
if True == string.isupper():
tmp = string.lower()
index = NewString.find(tmp)
NewString = NewString.replace(NewString, NewString.upper(), 1)
return NewString
OriginalString = 'eaAsqWAwaeqwerQwqRRRRRRRRRRRertwer'
print MainFunction(OriginalString)
朔夜
发表于 2017-10-19 09:47:33
def fun(temp):
items=list(str(e) for e in temp)
result=[]
array=['A','a','B','b','C','c','D','d','E','e','F','f','G','g','H','h','I','i','J','j','K','k','L','l','M','m','N','n'
,'O','o','P','p','Q','q','R','r','S','s','T','t','U','u','V','v','W','w','X','x','Y','y','Z','z']
for each in array:
if each in items:
num=items.count(each)
for a in range(0,num):
result.append(each)
print(result)
if __name__=='__main__':
test=str(input("输入一串字母混合大小写"))
fun(test)
colinshi
发表于 2017-10-19 14:13:59
ooxx7788 发表于 2017-4-10 21:02
其实我最初的想法,直接把26个字母按照大小写间隔写一遍,编成字典,直接把字母变成值排序,再变回来就 ...
感觉这个写的太棒了。。。。
我之前的思路是准备把所有字符转换成ASCII之后比较大小。但是没想到还能进行+True or False这种。。。太牛了
石小龙
发表于 2017-11-20 16:40:57
a = sorted('easqWAwaeq')
a.remove('W')
a.append('W')
b = ''.join(a)
print(b)
学习程序
发表于 2017-11-20 17:55:08
求鱼币
编程新血
发表于 2017-11-24 06:12:33
##按AaBbCc.....格式生成字符串
s2=''
for i in range(26):
s2+=chr(65+i)+chr(97+i)
##统计在给出的字符串中出现的次数,存到结果。
r=''
s='easqWAwaeq'
for i in s2:
su=s.count(i)
r+=i*su
print(s)
print(r)
xiangxz
发表于 2017-11-24 08:58:55
看看 哈哈
moc
发表于 2018-3-11 09:53:36
ooxx7788 发表于 2017-4-10 21:02
其实我最初的想法,直接把26个字母按照大小写间隔写一遍,编成字典,直接把字母变成值排序,再变回来就 ...
你的方法很好,但我有一点不明白,为什么在函数返回的时候要有*2,不要我觉得也可以啊,求解释?
1739266172
发表于 2018-3-11 11:14:13
ooxx7788 发表于 2017-4-10 21:02
其实我最初的想法,直接把26个字母按照大小写间隔写一遍,编成字典,直接把字母变成值排序,再变回来就 ...
+1
1739266172
发表于 2018-3-11 11:58:54
ooxx7788 发表于 2017-4-10 21:02
其实我最初的想法,直接把26个字母按照大小写间隔写一遍,编成字典,直接把字母变成值排序,再变回来就 ...
鱼币‘’‘啊哈哈’
1739266172
发表于 2018-3-11 11:59:25
鱼币,,,,,啊哈哈
victor.xu
发表于 2018-3-13 12:28:24
ooxx7788 发表于 2017-4-10 21:02
其实我最初的想法,直接把26个字母按照大小写间隔写一遍,编成字典,直接把字母变成值排序,再变回来就 ...
太厉害了,我都没看懂咋回事
shigure_takimi
发表于 2018-3-14 09:51:17
a = 'easqWAwaeq'
def sortedString(string):
string = sorted(string)
upperChars =
lowerChars =
for upperChar in upperChars:
for i in range(len(lowerChars)):
if upperChar.lower() <= lowerChars:
lowerChars.insert(i, upperChar)
break
else:
lowerChars.append(upperChar)
return ''.join(lowerChars)
print(sortedString(a))
恋恋鸢羽
发表于 2018-3-15 15:30:08
我爱 小甲鱼我爱小甲鱼 我需要鱼币学习 课后作业零基础啊
大头目
发表于 2018-3-30 13:33:35
def Rank(string):
r = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz'
list_r = []
list_r1 = []
result = ''
for each in string:
if each in r:
list_r.append()
list_r.sort()
for each in list_r:
list_r1.append(each)
for each in list_r1:
result += each
print(result)
Rank('easqWAwaeq')
凌九霄
发表于 2018-4-10 22:03:27
import random, string
lstr = random.sample(string.ascii_letters, 20)
print("原字符顺序:{0}".format(''.join(lstr)))
print("新排序字符:{0}".format(''.join(sorted(lstr, key=lambda x: ord(x.upper()) + ord(x.lower())))))
tsembrace
发表于 2018-4-11 16:50:32
'''
一个字符串仅包含大小写字母,现在要将其排序成一个新的字符串
次序为从a到z,且相同的大写和小写字母排在一起,大写在小写前。
如原字符串为'easqWAwaeq',排序后为'AaaeeqqsWw'
'''
def sortfunc(s):
n=ord(s)
if n<97:
return n+32-0.5
else:
return n
def sortstr(mystr):
return ''.join(sorted(mystr,key=sortfunc))
print(sortstr('easqWAwaeq'))
graceasyi
发表于 2018-4-11 17:04:17
def fun(s1):
s2 = list(s1)
s2.sort()
if s2.isupper():
count = len(s2)
for i in range(0, count):
for j in range(i + 1, count):
if s2.isupper() ^ s2.isupper():
if ord(s2) - ord(s2) < 32:
s2, s2 = s2, s2
else:
if ord(s2) < ord(s2):
s2, s2 = s2, s2
return ''.join(s2)
s1 = 'easqWAwaeq'
print(fun(s1))