python学习
#coding=utf-8 #2题===============取出整数成为一个字符串============== #str="sjdkf11kjsfdskl123121"; #str1=[]; #for num in str: # if num.isdigit(): # str1.append(num); #print "".join(str1); #第二种做法 #lists=list(str); #info=filter(lambda x:x.isdigit(),lists); #print ''.join(info); #3题=================统计字符出现次数==================== # strs="abcdsjfklsjflkajlkajklsfd"; # strs=strs.lower(); # dicts={item:strs.count(item) for item in strs}; # print dicts; #5题================去重字符串安装自然序排序============ # str="sdjfksljflkaaaalksjdflkjdslkfdslkj"; # a_list = list(str); # s_list = list(set(a_list)); # s_list.sort(reverse=False); # print ''.join(s_list); #--------------- #6题==============反转字符串输出======================= #str="1231ADFSSSFDSaasdfjdslkBBBjkdsjfslkdjklLKJDSLKFJSALK111"; # a_list = list(str); # a_list.reverse(); # print ''.join(a_list); # print str[::-1]; #===============大小写混合====================================== # str="1231ADFSSSFDSaasdfjdslkBBBjkdsjfslkdjklLKJDSLKFJSALK111"; # List_info = sorted(str); # a_upper_List=[]; # a_lower_list=[]; # for item in List_info: # if item.isupper(): # a_upper_List.append(item); # elif item.islower(): # a_lower_list.append(item); # for y in a_upper_List: # y_lower = y.lower(); # if y_lower in a_lower_list: # num=a_lower_list.index(y_lower); # a_lower_list.insert(num,y); # print "".join(a_lower_list); #=======================判断字符串是否出现对应字符串里面============== # str="abcdefghioy"; # search="boy"; # list_search=list(search); # from_str=set(str); # from_str.update(list_search); # len1=len(list(from_str)); # len2 = len(str); # if len1 == len2: # print 1; # else: # print 2; #===============判断boy,girl是否出现在a字符串里面=================== # str="abcdefghioyrl"; # search=['boy','girl']; # target_str=set(str); # for item in search: # target_str.update(item); # if len(str) == len(target_str): # print 111 # else: # print 2222; #==============统计字符串a出现次数最高字符======================= # str="afsjlkfajslkfakskjfdakjfsakjfsaaaaa"; # dict={}; # for item in str: # num = str.count(item); # dict[item]=num; # newdict = sorted(dict.items(),key=lambda item:item[1], reverse=True); # print newdict; #==============