how to compare two strings in python?

0 votes
can you give any examples?
Mar 25 in Python by Waseem
• 4,480 points
53 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 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,520 points

edited Dec 11, 2018 by Nymeria 204 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,720 points
203 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,340 points
40 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 May 20 in Python by Mohammad
• 3,170 points
570 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 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 424 views
+4 votes
6 answers
+4 votes
7 answers
+2 votes
11 answers