#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    2
    Rep Power
    0

    Program not working as expected.. Some one help me by modifying my code


    python Code:
    ## To check S2 characters are there in S1 or not.
     
    S1=list("bothofthemWhatisthetimecomplexitydoopers")
    S2=list("dooper")
    D1={}
    for i in S1:
    if i in D1:
    D1[i]=D1[i]+1
    else:
    D1[i]=1
     
    for j in S2:
    print j,S2
    if j in D1:
    S2.remove(j)
    else:
    print "not in list"
     
    if len(S2) == 0:
    print "OK"
    [CODE]
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Location
    39N 104.28W
    Posts
    158
    Rep Power
    3
    I can't tell what you're trying to do. What is the program doing and what do you want it to do?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    2
    Rep Power
    0
    Originally Posted by rrashkin
    I can't tell what you're trying to do. What is the program doing and what do you want it to do?
    S1=list("bothofthemWhatisthetimecomplexitydoopers")
    S2=list("dooper")

    if all the chars in S2 are there in S1 or not.
    Thats what i want to say
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,856
    Rep Power
    481

    Use sets


    Code:
    # learn the fundamental python data types.
    
    S1 = set("bothofthemWhatisthetimecomplexitydoopers")
    S2 = set("dooper")
    print(S1.intersection(S2) == S2)

    Comments on this post

    • rrashkin agrees : SLICK!
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo