[SOLVED] seeking how to merge

Issue

This Content is from Stack Overflow. Question asked by Kelly

New to python here… is my code still salvageable? Here’s a snippet of me trying to find the amount of times a letter in the alphabet (both upper and lower case) shows up in a text paragraph. This code successfully works for making two separate lists of lower and upper case letters, but I’m trying to merge them into one. I thought I could input a def merge() but it didn’t work and I have a feeling I might have to start completely over.

small_letter_status = [0]*26
capital_letter_status = [0]*26

for x in txt:
    if x>='a' and x<='z':
        small_letter_status[ord(x)%ord('a')] += 1
    elif x>='A' and x<='Z':
        capital_letter_status[ord(x)%ord('A')] += 1

print("nSmall Letter count")
for x in range(len(small_letter_status)):
    print(chr(x+(ord('a'))), small_letter_status[x])

print("nCapital Letter count")
for x in range(len(capital_letter_status)):
    print(chr(x+(ord('A'))), capital_letter_status[x])



Solution

You can simply merge lists using + operator

print([1, 2, 3] + [4, 5,6])
-> [1,2,3,4,5,6]


This Question was asked in StackOverflow by Kelly and Answered by Vazno It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?