Skip to main content
  1. About
  2. For Teams
Asked
Viewed 304 times
-1

I am trying to use .pop to check the pangram and have the following code but get the error "'str' object has no attribute 'pop'". I am new to programming. Please help.

import string

def ispangram(str1, alphabet=string.ascii_lowercase):
    for x in str1:
        if x in alphabet:
            alphabet.pop[0]
        else:
            pass
    return len(alphabet)==0
3
  • string.ascii_lowercase is a string, not a list or dict, so it lacks the pop attribute
    C.Nivs
    –  C.Nivs
    2020-05-03 17:10:20 +00:00
    Commented May 3, 2020 at 17:10
  • Following up @C.Nivs, also even if it was a list or dict, it would be a method, not an attribute.
    iamvegan
    –  iamvegan
    2020-05-03 17:14:27 +00:00
    Commented May 3, 2020 at 17:14
  • @iamvegan I think that borders on semantics, especially when calling a non-existent method raises an AttributeError
    C.Nivs
    –  C.Nivs
    2020-05-04 00:32:49 +00:00
    Commented May 4, 2020 at 0:32

2 Answers 2

0

One approach is to use sets:

import string 

def check(s):
    """ 
    Return True if string s is Panagram
    """
    alphabet=string.ascii_lowercase
    return set(alphabet) - set(s.lower()) == set([])

PS: If you want to see what attributes/methods of an object just use dir(<object>)

Sign up to request clarification or add additional context in comments.

Comments

0

List and dictionary objects only have popmethod.You are trying to delete the character in the 0th index of string. Thus you can try this :

def ispangram(str1, alphabet=string.ascii_lowercase):
    for x in str1:
        if x in alphabet:
            alphabet = alphabet[1:]
        else:
            pass
    return len(alphabet)==0

output

print (ispangram("The quick brown fox jump over the lazy dog", "s"))

False

Comments

Your Answer

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.