Questions tagged as 'python'

3
answers

How to compress code in python 3?

I wanted to leave this little bit of code in a single line ... i = int(input()) for j in range(1,i+1): if(i%j==0): print(j) Is it possible?     
asked by 13.08.2018 / 21:30
2
answers

Python calling super () on a class that does not implement inheritance

I'm developing some middlewares and delving into the Django source code I came across the following: class MiddlewareMixin: def __init__(self, get_response=None): self.get_response = get_response super().__init__() de...
asked by 05.08.2018 / 21:16
2
answers

How to have two counters on the same repeat loop?

I have the following structure in my code: for c in range(0, len(str(ListaTemp[4]))): for c2 in range(c+1, len(str(ListaTemp[4]))): if str(num)[c] == str(num)[c2]: valido = True And so. My teacher is going to give on...
asked by 21.06.2018 / 18:44
4
answers

Function that returns the element with more characters in a list

I came up with the following function: def func6a(lista): maior = 0 for el in lista: if type(el) == list: maior = func6a(el) else: if len(el) > maior: maior = el return m...
asked by 27.05.2018 / 23:34
1
answer

How to return series of values in Python

I have a function that reads line by line a TXT file to disk and formats it extracting only what interests me, getting a list like this: Swi 04/11/2018 Basel Lugano 3 2 2 0 Swi 03/11/2018 Grasshopper Young Boys 0 3 0 0 Swi 04/11/2018 Luzern Zü...
asked by 07.11.2018 / 10:08
2
answers

how to delete a column in a csv python file

How do I delete a column from a csv file? example: nome;nota;idade joao;10;12 maria;8;13 jose;6;8 to look like this: nome;idade joao;12 maria;13 jose;8 How do I put a new column of this file into another file? I'm still learning pro...
asked by 22.11.2018 / 14:13
1
answer

What's wrong with this python code?

import urllib.request import time def send_to_twitter(): import sys import tweepy CONSUMER_KEY = '1wrnsF5lB8fEWVzRdvlIqdTl' CONSUMER_SECRET = 'eTiylDUHLJgGnTCcxzzCtzHXG4OlHrbY6wLvuZUnAEhrokyNA' ACCESS_KEY = '2325915097-q2JYaZ...
asked by 06.01.2017 / 16:30
2
answers

Restrict __setattr__ when the attribute does not exist within the instance in Python

Hello, I need to know how I can assemble a class that can not have attributes implemented after the instance. Ex: class Foo(object) def __init__(self, a='hello', b='world') self.a = a self.b = b __setattr__(self, key,...
asked by 06.09.2016 / 19:05
3
answers

How to create a variable through the user-typed response in Python?

For example, we can use this code to assign the value to a variable: idade = input('Digite sua idade: ') What I would like to know is if, instead of assigning a value to a variable, is it possible to create a variable by naming it with...
asked by 30.12.2016 / 16:58
2
answers

Django + Python update and not insert

I'm using a filter to return some student and update their data, however when I try to save I get the following error:    Student with this CPF already exists and Student with this RA already exists. My views.py : from django.s...
asked by 03.09.2018 / 16:34