Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
How to sort the letters in a string alphabetically in Python without using join()? Using join() we can do this:
def sort_string(a)
return ''.join(sorted(a))
Is there a way to sort string without using join()?
Your solution is correct as strings are immutable in python. So, it's impossible to change (in your case - sort) an existing string. You have to create new one (you do it with join() call).
Also, good notes about sorting letters in string in python can be found here: How to sort the letters in a string alphabetically in Python
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 days ago.
Improve this question
I am new to python and I'm working on a practice program called password generator. So I've managed to generate random passwords in sequence, first letters, then symbols and numbers. The next step is to shuffle all the characters where I get stuck. I figured I could first add some spaces into the string using join() and then use split() to convert the string into a list. But an invalid syntax error keeps coming up, I'm really confused.
This is how I shuffle the password string:
password_str=" "join.(password_in_sequence)
#characters = password_str.split(" ")
random.shuffle(characters)
password=""
for character in characters:
password+=character
print(password)
Please tell me where I went wrong, and maybe some simplified solutions?
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
How can I find common substrings of two strings in order to show changes/edit of a string?
So what I try to do is to compare an old version of a string:
string_old = "My name is pm730! How are you?"
with a new/edited version of the string:
string_new = "My name isn't pm730, it is pm740!"
Deleted substrings are not important. New substrings should be distinguished somehow, so that I could output it like this eventually:
My name isn't pm730 , it is pm740!
This task sounds easy but is more complicated than I thought. So my hope is that there is already an similar implementation available, but unfortunanly I can't find it...
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am starting to learn about the hash table data structure in C, and I've noticed (if I understand the concept correctly) that hash tables are awfully similar to python dictionaries. If I am incorrect and they are two completely different things, could someone explain to me what a hash table is without getting too technical? Thanks.
There is not really any difference between them. That's why python's dicts don't support duplicates. That is also why python has the function hash which python's dictionaries use by default.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
How can I match strings that are not inside a set of strings using python regular expressions?
Ex: set of strings ('/abc|/bcd')
I want to match any string other than that in the parentheses. That should be exact match.
Here's a fun one for you:
^(?!\/(?:abc|bcd)$).+
It uses a negative lookahead to ensure that the string being matched isn't one of the strings you don't want, then grabs whatever else is left.
Demo on Regex101
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I know about foo = [] being shorthand for foo = list() and I was wondering if there was a list of shorthand notations for creating empty dictionaries, tuples, sets, etc. I'm specifically looking for Python 3.x but either one would be useful to have.
To create an empty dictionary, use {}.
To create an empty tuple, use ().
There is no shortcut for an empty set.
As for the etc., I don't know what else you are thinking of.