1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| s = """there's_a_girl_but_i_let_her_get_away it's_all_my_fault_cause_pride_got_in_the_way and_i'd_be_lying_if_i_said_i_was_ok about_that_girl_the_one_i_let_get_away i_keep_saying_no this_can't_be_the_way_we're_supposed_to_be i_keep_saying_no there's_gotta_be_a_way_to_get_you_close_to_me now_i_know_you_gotta speak_up_if_you_want_somebody can't_let_him_get_away_oh_no you_don't_wanna_end_up_sorry the_way_that_i'm_feeling_everyday no_no_no_no there's_no_hope_for_the_broken_heart no_no_no_no there's_no_hope_for_the_broken there's_a_girl_but_i_let_her_get_away it's_my_fault_cause_i_said_i_needed_space i've_been_torturing_myself_night_and_day about_that_girl_the_one_i_let_get_away i_keep_saying_no this can't be the way we're supposed to be i keep saying no there's gotta be a way to get you there's gotta be a way to_get_you_close_to_me you_gotta speak_up_if_you_want_somebody can't_let_him_get_away_oh_no you_don't_wanna_end_up_sorry the_way_that_i'm_feeling_everyday no_no_no_no there's_no_hope_for_the_broken_heart no no no no there's no hope for the broken no home for me no home cause i'm broken no room to breathe and i got no one to blame no home for me no_home_cause_i'm_broken about_that_girl the_one_i_let_get_away so_you_better speak_up_if_you_want_somebody you_can't_let_him_bet_away_no_no you_don't_wanna_end_up_sorry the_way_that_i'm_feeling_everyday don't_you_know no_no_no_no there's_no_hope_for_the_broken_hearty don't you know no no no no there's no hope for the broken oh you don't wanna lose at love it's only gonna hurt too much i'm telling you you_don't_wanna_lose_at_love it's_only_gonna_hurt_too_much i'm_telling_you you_don't_wanna_lose_at_love cause_there's_no_hope_for_the_broken_heart that_girl the_one_i_let_get_away """ out = {} for i in s: out.update({i:s.count(i)}) out = sorted(out.items()) print(out)
''' [('\n', 66), (' ', 71), ("'", 40), ('_', 245), ('a', 104), ('b', 30), ('c', 15), ('d', 29), ('e', 169), ('f', 19), ('g', 38), ('h', 67), ('i', 60), ('k', 20), ('l', 39), ('m', 28), ('n', 118), ('o', 165), ('p', 26), ('r', 61), ('s', 51), ('t', 133), ('u', 45), ('v', 7), ('w', 34), ('y', 62)] 没有数字,没有case以外的统计,根据规则重新整理一下数组排序:
[('a', 104), ('b', 30), ('c', 15), ('d', 29), ('e', 169), ('f', 19), ('g', 38), ('h', 67), ('i', 60), ('k', 20), ('l', 39), ('m', 28), ('n', 118), ('o', 165), ('p', 26), ('r', 61), ('s', 51), ('t', 133), ('u', 45), ('v', 7), ('w', 34), ('y', 62),(' ', 71),('_', 245)] '''
|