I am fairly new to python and I am trying to figure out how to find if the elements of a list equal a given string?
lists=["a","b",'c']
str1='abc'
I know it is probably easy, but I am having a hard time without using string methods.
Thanks, DD
you can use .join to create a string from your list:
list = ['a', 'b', 'c']
strToComapre = ''.join(list1)
Now you can check if strToComapre is "in" the original str:
if strToCompare in originalStr:
print "yes!"
If you want a pure compare use:
if strToCompare == originalStr:
print "yes! it's pure!"
There are lots of options in python i'll add some other useful posts:
is. Sometimes it works thanks to string interning, but == is what really works.