Python Forum
Find first letter from a list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Find first letter from a list
#1
Hello. I have function that finds first letter in all words from list. And I want to count all lower cases. I don't understand why quantity updates only once.
arr=[["Hello","how","are","you"],["I","am","fine"]
def first_letter(x):
    abc = "abcdefghijklmnopqrstuvwxyz"
    quantity=0
    for j in range(0,len(x)):
        letter= x[j][1]
        if x[j][1] in abc:
            quantity=+1
            
            
    print(quantity)
Reply
#2
Because you are using '=+1' (set to positive one) instead of '+=1' (add one in place).
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
(Nov-27-2019, 10:52 PM)ichabod801 Wrote: Because you are using '=+1' (set to positive one) instead of '+=1' (add one in place).
Thanks stupid mistake, maybe you know THE best way how to find if second word, third letter is UPPERCASE?
Reply
#4
words[1][2].isupper()
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  look at first letter in list and append word for assertion mapypy 3 1,899 Feb-06-2021, 05:45 PM
Last Post: buran
  How to find difference between elements in a list? Using beginner Basics only. Anklebiter 8 4,261 Nov-19-2020, 07:43 PM
Last Post: Anklebiter
  To find the index of the first occurrence of the key in the provided list Angry_bird89 4 3,194 Jun-20-2020, 06:53 PM
Last Post: Angry_bird89
  How do you find the length of an element of a list? pav1983 13 4,792 Jun-13-2020, 12:06 AM
Last Post: pav1983
  Find 'greater than' items in list johneven 2 4,430 Apr-05-2019, 07:22 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020