Skip to content

Tag: python

python split a string with at least 2 whitespaces

I would like to split a string only where there are at least two or more whitespaces. For example Results: I would like it to look like this: Answer Where s matches any whitespace character, like tnrfv and more {2,} is a repetition, meaning “2 or more”

Convert list to tuple in Python [duplicate]

This question already has answers here: Why does code like `str = str(…)` cause a TypeError, but only the second time? (20 answers) Closed 7 days ago. I’m trying to convert a list to a tuple. Most solutions on Google offer the following code: However, the code results in an error message when I ru…

Sort dict in jinja2 loop

I’m still learning jinja2 and flask and I’m having a difficulty using dictsort in jinja2. So I’m passing this dict into a jinja2 template: What I want is create a table that is sorted by the value of the key ‘totalpts’. I tried all sort of things and it just doesn’t take to…

Reason for globals() in Python?

What is the reason of having globals() function in Python? It only returns dictionary of global variables, which are already global, so they can be used anywhere… I’m asking only out of curiosity, trying to learn python. I can’t really see the point here? Only time I would need it, was if I …