Questions tagged as 'python'

1
answer

Differences between Python and JavaScript in relation to arrays?

I'm having a hard time because in JavaScript it was possible to do this: const x = [] x[0] = 1 x[1] = 2 But in Python when I create an empty list and try to make a statement it says the index is out of range. I can work around the append...
asked by 07.10.2017 / 15:52
1
answer

How to work with more than one python file?

I learned to import modules, but I do not know how to, for example, create a class in a separate file and include it in the main program, how to do that?     
asked by 06.10.2017 / 18:16
2
answers

Print the largest substring of s where letters occur in alphabetical order

Let s be a string with all lowercase characters. Write a program that prints the largest substring of s in which letters occur in alphabetical order. For example: s = 'azcbobobegghakl' The program should print: beggh If there a...
asked by 16.04.2018 / 00:29
2
answers

How to make powers of 9 quickly

I'm asking a question that asks to raise the number to 9 and say the last digit I got, but the resolution seems to have passed the time because it had a number of 10 ^ 9, how to solve it in a faster way My code import math while True: try:...
asked by 23.05.2018 / 19:48
2
answers

input () and raw_input ()

According to the Python 2.x documentation, it is recommended to use the raw_input function instead of input . Conversely, in the Python 3.x documentation, the raw_input function does not even appear. So does the input...
asked by 08.08.2016 / 01:07
2
answers

Find higher and lower single values Python

I'm trying to find the smallest and highest single value of a python array, but something is still flawed. def pegaExtremosUnicos(v): i = 1 for i in range(len(v)): atual = v[i] j = i - 1; while (j >=0) and (a...
asked by 08.08.2016 / 01:22
1
answer

Creating a program to get important news on a site

from bs4 import BeautifulSoup import requests url = 'http://g1.com.br/' header = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) ' 'AppleWebKit/537.36 (KHTML, like Gecko) ' 'Chrome/51.0.2...
asked by 02.08.2016 / 03:28
3
answers

How to check if a number is within a range in Python?

In Python, I would like to check if a number is within a range. Is there a more pythonic way than the following code? if n >= 100 and n <= 200: ...     
asked by 24.08.2016 / 19:25
2
answers

List in Python with non-repeated values without using set function?

How can I create a list from the sum of two previous ones without some value appearing repeated, without using the set function? Example: >>>a = [1, 2, 3] >>>b = [3, 4, 5] >>>c = a + b >>>print c [...
asked by 19.03.2016 / 03:23
2
answers

swap shell commands

The command python foo.py When called on the terminal, it runs the sent python file. Imagine that I have a python file that always needs to be called as follows: xvfb-run python foo.py to work. Is there any way I can write something...
asked by 27.05.2015 / 14:40