-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
C.Nivs
  • 12,353
  • 2
  • 19
  • 44
Barsha
  • 1
  • `string.ascii_lowercase` is a string, not a list or dict, so it lacks the `pop` attribute – C.Nivs May 03 '20 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 May 03 '20 at 17:14
  • @iamvegan I think that borders on semantics, especially when calling a non-existent method raises an `AttributeError` – C.Nivs May 04 '20 at 00:32

2 Answers2

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
Sarangan
  • 868
  • 1
  • 8
  • 24
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>)

dejanualex
  • 3,872
  • 6
  • 22
  • 37