Hello,
I have some problem with checking if the element is contained in the list or not.
For example:
a = ['abc', 'def', 'gh', 'i']
b = 'abc'
Following is my code: - def is_proper_word(b, a) :
-
-
is_proper = False
-
for b in proper_word_list:
-
is_proper = True
-
return is_proper
-
Is it correct?
Thank you in advance.
4 2184 Glenton 391
Recognized Expert Contributor
Hi
With a and b as you suggest
returns True.
It seems unnecessary to do more work than this single line, but if you have a reason post back.
Actually post back anyway to let us know how it goes.
Glenton 391
Recognized Expert Contributor
By the way, your code would not work. It would simply create a loop of all the variables in proper_word_list, (which isn't defined anyway), calling the items in the list variable b. It would just over-write the b variable that you input.
@Jimmy45
You could use list comprehension,
[elem for elem in a if elem == b]
Glenton 391
Recognized Expert Contributor
Oh, if you're wanting to do it that way, you could use numpy arrays with a in b giving a boolean numpy array. Depends what you want to do really.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Holger Butschek |
last post by:
Hy folks,
I have a problem in Zope (DTML).
I know, that it's a very simple problem, but I'm quite new to Zope.
I want to check, if a sequence-item of a sql-statement is in a list called
groupsSW (this list might or might not be given by URL from a previous
window).
|
by: xerix |
last post by:
I'm trying to make a function which insert an object into a list and returns
an iterator to the new element in the list. But as far as I know there is no
function which returns an iterator to the last element of a list. (.end()
returns an iterator one item past the end of the list) How could I solve
this?
|
by: arvind.nm |
last post by:
hi,
if i create a linked list like list<char> stk;
if i want to remove the first element from the list and i write
stk.pop_front() the node is still present but the char stored is now
'\0',why? how can i delete the first node. will
stk.erase(stk.begin()) work?
|
by: Vijay |
last post by:
Hi,
Iam new to VC++6.0.
I want to display selected item of the ListBox in a MessageBox. I know for
experience ppl it must be a kids play but for me who had worked in C# and
VB, it seems to be little different.
Can anyone write couple to lines of code for this?
Moreover, If I want to insert any element at the mth place of nth col in
list box...
|
by: Howard |
last post by:
Is there an easy way to get an iterator (*not* a reverse-iterator) to the
last element in a list? The last() function returns the element itself, not
an iterator.
Thanks,
-Howard
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |