in Education by
I have a given list of string and a list of characters and I want to check the string with containing a specific character. Here is an example: Dictionary = ["Hello", "Hi"] Character = ['e','i'] it must return a "Hello" else empty list I am comparing a list of characters with a list of strings but it is giving me a type error. Dictionary = ["Hello", "Hi"] Character = ['e'] emptystring = "" def findwords(dictionary,character): for i in dictionary,character: for j in dictionary: if character[i] == dictionary[i][j]: return dictionary[i] else: j+=1 i+=1 return emptystring k = findwords(Dictionary,Character) k TypeError Traceback (most recent call last) in ----> 1 k = findwords(Dictionary,Character) 2 k in findwords(dictionary, character) 5 for i in dictionary,character: 6 for j in dictionary: ----> 7 if str(character[i]) == str(dictionary[i][j]): 8 return str(dictionary[i]) 9 else: TypeError: list indices must be integers or slices, not list JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Check this. Dictionary = ["Hello", "Hi"] Character = ['e'] def findwords(dictionary,character): tmp = "" for i in dictionary: #convert string to char list str_arr = list(i) for j in character: #if char is in char list then save it in tmp variable #if you want multiple values then use array instead of tmp if j in str_arr: tmp = i return tmp k = findwords(Dictionary,Character) print(k)

Related questions

0 votes
    I want to create a new list from the existing two lists that will have all the matches from list 2 which has an exact ... *", i) in a] Select the correct answer from above options...
asked Jan 25, 2022 in Education by JackTerrance
0 votes
    I tried to convert data from the list of strings into a Map with the Stream API. But the way I ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 3, 2022 in Education by JackTerrance
0 votes
    please see my code below, example_list = [ ['a','b','c'], ['f','g','h'], ['i','j','k'], ] my_string = ''' ' ... g','h'), ('i','j','k'); Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    What would be your preferred way to concatenate strings from a sequence such that between every two consecutive ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    I want my Python function to split a sentence (input) and store each word in a list. My current code splits ... the word print(words) Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I have a List : Old_list =['orders_ce_deduped.01.csv','orders_ce_deduped.02.csv'] I need to get the 01 and 02 part ... = ['01','02'] Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    Which of these class is used to read characters and strings in Java from console? (a) BufferedReader (b) ... & Applets of Java Select the correct answer from above options...
asked Feb 24, 2022 in Education by JackTerrance
0 votes
    I've set two variables to the value 'qwerty' in Python. In a conditional expression which fails i.e. var1 is ... mistakes I am doing? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    I am confused about the usage of string.join(list) instead of list.join(string), for instance see this code: ... reason behind this? Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    I need to show Czech characters in PyCharm and Kivy apps. The encoding of the file is UTF-8, but ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 29, 2022 in Education by JackTerrance
0 votes
    I want to install MySQL_python adapter (v1.2.2) using a new virtual env I created with a - -no-site-packages ... How can I do it? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    List strings = Arrays.asList("abc", "", "bc", "efg", "abcd","", "jkl");...
asked Nov 8, 2020 in Education by Editorial Staff
0 votes
    Liststrings = Arrays.asList("abc", "", "bc", "efg", "abcd","", "jkl");...
asked Nov 8, 2020 in Education by Editorial Staff
0 votes
    In Python, How to remove trailing and leading whitespace from str ? For instance check this: " Hey" --> "Hey" " ... "Harsh has a dog" Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
...