how to compare two strings in python?

0 votes
can you give any examples?
Mar 25 in Python by Waseem
• 1,910 points
18 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes
compare two string in python 
>>> s1="abc def ghi"
>>> s2="def ghi abc"
>>> s1 == s2 
False
>>> sorted(list(s1)) == sorted(list(s2))  For comparing if they have same characters. 
True
>>> sorted(list(s1))
[' ', ' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
>>> sorted(list(s2))
[' ', ' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
another method
if same character than this method apply 


>>> s1="abc def ghi"
>>> s2="def ghi abc"
>>> from collections import Counter
>>> Counter(string1) == Counter(string2)
True
if you know more about python concept and also string related concept than you can join
answered Mar 25 by rajesh
• 1,210 points

Related Questions In Python

0 votes
1 answer

How to calculate time interval between two time strings in Python

Try doing this - It is efficient for ...READ MORE

answered Nov 29, 2018 in Python by Nymeria
• 3,500 points

edited Dec 11, 2018 by Nymeria 74 views
0 votes
1 answer

How can I compare the content of two files in Python?

Assuming that your file unique.txt just contains ...READ MORE

answered Apr 16, 2018 in Python by charlie_brown
• 7,710 points
33 views
0 votes
1 answer

How to format strings in python?

To answer your first question... .format just seems more ...READ MORE

answered Oct 1, 2018 in Python by ariaholic
• 7,320 points
18 views
0 votes
1 answer

How can I write a program to add two numbers using functions in python?

def add(a,b):      return a + b #when i call ...READ MORE

answered 5 hours ago in Python by Mohammad
• 1,400 points
6 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
19 views
+4 votes
6 answers
+4 votes
7 answers
+2 votes
11 answers

How to print array/ list without brackets in python?

name=["a","b","c"] print (', '.join(name)) It will simply take all ...READ MORE

answered Apr 18, 2018 in Python by aayushi
• 750 points
11,677 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.