python - Determining if a Part of a string is in a List -


given input

guess='1 5k' 

and list

playable=['ac','qs','5s','5k','kc'] 

how go determining if '5k' part of guess in playable? also, if in playable, how go determining if item 1 spot left of has either '5' or 'k' in it. playable become

playable=['ac','qs','5k','kc'] 

with '5k' replacing '5s'. far have

def onec(guess):     split_em=guess.split() ##splits @ space     card_guess=split_em[1] ##gets '5k' part of string     if card_guess in playable:                                           ##confusion area         index1=playable.index(card_guess) ##finds index of '5k'         index_delete= del playable[index1-1] ##deletes item left of '5k' 

my problem right i'm not sure how determine if '5' or 'k' in item 1 spot left. there way turn '5k' set of ('5','k') , turn element 1 spot left ('5','s') , run intersection on them? wrote on phone because internet down @ house sorry confusion or misspellings. time!

you can iterate on characters in item left , see if '5' or 'k' in there:

index1 = playable.index(card_guess) if any(c in playable[index1 - 1] c in card_guess):     del playable[index1] 

note above code not check case index1 == 0 you'd have define happens when guessed card first card in list.

so answer question: for c in card_guess iterates on characters in "5k" (which '5' , 'k' , checks if of in playable[index1 - 1], item left of "5k").


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -