how to compare two strings in python?

0 votes
can you give any examples?
Mar 25, 2019 in Python by Waseem
• 4,540 points
215 views

1 answer to this question.

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, 2019 by rajesh
• 1,230 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,520 points

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

How to compare two string with some characters only in python?

You could use in to check if a string ...READ MORE

answered 3 days ago in Python by Gitika
• 51,280 points
9 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,780 points
1,104 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 aryya
• 7,400 points
106 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,571 views
0 votes
0 answers
+4 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,800 points
1,191 views
+4 votes
7 answers
+2 votes
11 answers