Questions tagged as 'python'

1
answer

What are the differences between Flask and Django?

I started shortly in the Python language and am currently working on a project using Flask , MariaDB and WebSockets . I see people talk a lot about Django and would like to know the differences between two.     
asked by 23.08.2017 / 09:45
2
answers

eval vs ast.literal_eval: what are the differences?

In Python it's common to read that ast.literal_eval is an alternative to eval . Are the functions equivalent? What does one do to another also? In security issues, is there priority in using one or the other? What are th...
asked by 03.09.2018 / 14:37
2
answers

In Python, is there any rule or advantage over using 'Self'?

Consider the examples below: Example 1: > class PrintText(): > def __init__(self): > text = 'Funciona!' > self.printa(text) > > def printa(self, text): > print(text) Example 2...
asked by 09.07.2014 / 17:38
1
answer

How to sort a list of tuples by the nth element?

I have a list of tuples of the form: [(0, 1), (2, 3), (4, -5), (6, -3)] I want to sort this list by the second value of each tuple (that is, in case we would have [(4, -5), (6, -3), (0, 1), (2, 3)] . How to do that?     
asked by 14.12.2013 / 23:00
6
answers

Convert an array of floats to integer

Suppose the following: import numpy as np a = np.array ( [1.1, 2.2, 3.3] ) How to convert this array to int without having to iterate each element or using another array? Why to: b = int(a) It gives an error because it is on...
asked by 06.01.2014 / 00:50
1
answer

When should I use __init__ in functions within classes?

From the book I'm studying, at times the author uses __init__ as being a first function of a class. This function (and others) always have self as one of the variables (something that I still do not understand why). When should (an...
asked by 19.01.2016 / 03:04
1
answer

Parallel sorting algorithm Odd-even sort in python

I created the following serial code to perform the Odd-even sort ordering, which first sorts the odd / even and odd / even indices. import time def oddevenSort(x): sorted = False while not sorted: sorted = True #orden...
asked by 20.06.2017 / 21:30
1
answer

Vectors and Angles (Molecular Geometry)

Hello, I have a problem, more mathematical than computational, to solve, but I have not been able to solve it myself until now ... I have a set of 3 atoms connected to each other forming an angle X between the bond. I need to implement a c...
asked by 19.07.2014 / 18:52
4
answers

Program that returns the non-common numbers of two lists (python)

I'm trying to make a program, in Python, that returns a list with elements not common between two other lists. I made the following code: def indice(a,b): ind = [] for i in range (len(a)): for w in range (len(b)): i...
asked by 30.03.2017 / 03:33
4
answers

Is there any way to comment Multiple lines in Python?

To comment on a line, we use # . I would like to know if you can comment on multiple lines in Python 3. If yes, how should I do it?     
asked by 22.01.2018 / 18:35