Questions tagged as 'python-2.7'

1
answer

Displaying certain values in Python

I need help with the following: I have a variable that generates random integers from (0 to 400). In a certain number of executions, I want the value (s) and position (s) of the lower value (s) to be 100. I have a code (see below) that I...
asked by 26.02.2017 / 18:41
1
answer

Create a list copy in Python so that they are independent

I have the following situation: I have list_1 with the following values [10,20,30,40]. I want to create a copy of this list, however I need the list_2 not to change when I modify some value in list_1. I have the following code below, bu...
asked by 04.03.2017 / 01:01
1
answer

Import data from Mysql to Excel

I want to import data from Mysql to excel using Python, when I try to make it a tuple error. Can anyone with more experience help me? I followed the code and the error: # coding=utf-8 from Tkinter import * from os import popen import tkM...
asked by 21.09.2016 / 19:11
2
answers

Python accumulator list

I'm developing a function that takes 3 parameters fctn (function, list, element) and you have to return a list with the intermediate states of the accumulator, as in the example below: >>> fctn(lambda acc, x: acc + x, [1, 2, 3, 4], 0)...
asked by 09.04.2017 / 17:42
1
answer

Sublime Text 2 build gives a different result from iPython on the command line

I'm trying to migrate to Sublime Text 2 and do everything without leaving the program. Before I ran a script with the following line: from scipy.stats import beta, bernoulli, gaussian_kde No shell within iPithon the command ru...
asked by 08.03.2014 / 17:55
1
answer

Imports within functions in Python

I've seen cases where the developer does the import of a module within a function, some cases mainly in the documentation of Django, why it was not very clear to me, if anyone can help me thank you.     
asked by 11.07.2018 / 01:43
1
answer

How do I extract the names of several folders within a directory?

I need to enter into a folder called / users , where inside it to several folder and copy the name of all folders, follow the example. I wanted to be able to get the name of these folders and save them to a list in python.     
asked by 17.05.2018 / 19:49
1
answer

Remove repeated words using python

I have a text file with many words repeated. I need every word in the file to appear only once. import codecs wordList = codecs.open('Arquivo.txt' , 'r') wordList2 = codecs.open('Arquivo2.txt', 'w') for x in range(len(wordList)) : f...
asked by 06.09.2017 / 01:42
1
answer

Create a 2D vector from a 1D vector in Python

I have a vector with the following values: a = [10, 20, 30, 40, 50, 60, 70, 80] I need to create 2D vector with these values. For example, it would have to look like this: b = [[10, 20], [30,40], [50,60], [70,80]] Could someone p...
asked by 11.08.2017 / 18:59
1
answer

How to extract specific data from a text file with Python?

I have a * text file of 49633 lines (file.txt) in the following format: -e Tue Mar 28 20:17:01 -03 2017 total used free shared buffers cached Mem: 239956 126484 113472 4904 1...
asked by 05.08.2017 / 22:55