- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
A unique string in Python
Suppose we have a string s, we have to check whether it has all unique characters or not.
So, if the input is like "world", then the output will be True
To solve this, we will follow these steps −
set_var := a new set from all characters of s
return true when size of set_var is same as size of s, otherwise false
Let us see the following implementation to get better understanding −
Example
class Solution: def solve(self, s): set_var = set(s) return len(set_var) == len(s) ob = Solution() print(ob.solve('hello')) print(ob.solve('world'))
Input
hello world
Output
False True
Advertisements