how to compare two strings in python

0 votes
can you give any examples?
Mar 25, 2019 in Python by Waseem
• 4,540 points
906 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,270 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,560 points

edited Dec 11, 2018 by Nymeria 2,934 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 Nov 26, 2020 in Python by Gitika
• 65,910 points
578 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
2,368 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,450 points
530 views
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,067 views
0 votes
1 answer
+5 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,790 points
3,485 views
+4 votes
7 answers
+1 vote
12 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP