python

How to use python to merge two lists using common elements?

How to use python to merge two lists using common elements? Question: I have two lists in python, the first with each element composed by a string and an integer: delta[0:10] [(‘conhecimento’, 17), (‘ciência’, 14), (‘interdisciplinaridade’, 13), (‘saber’, 10), (‘objeto’, 10), (‘pode’, 10), (‘processo’, 9), (‘conceito’, 9), (‘assim’, 8), (‘mundo’, 8)] And a second list …

Total answers: 2

pandas lambda with multiple arguments

pandas lambda with multiple arguments Question: Assume there is a DataFrame such as import pandas as pd import numpy as np df = pd.DataFrame({‘A’:[21, 11, 31, 45], ‘B’:[10, 20, 10, 11], ‘C’:[57, 22, 34, 10]}) A B C 0 21 10 57 1 11 20 22 2 31 10 34 3 45 11 10 I …

Total answers: 2

Create folders with file name and rename part of it

Create folders with file name and rename part of it Question: i have some pdfs files that i need to create folders with part of your name and move the pdfs to the folders. cwd = os.getcwd() padrao = ‘_V1_A0V0_T07-54-369-664_S00001.pdf’ for file in glob.glob("*.pdf"): dst = cwd + "\" + file.replace(str(padrao), ”).replace(‘P’, ”) os.mkdir(dst) shutil.move(file, …

Total answers: 1

100 Prisoners Dilemma – Python code isn't working

100 Prisoners Dilemma – Python code isn't working Question: I stumbled across an interesting probability problem about half an hour ago. https://en.wikipedia.org/wiki/100_prisoners_problem Essentially, there are 100 boxes, drawers, etc, each with a unique number between 1-100 inside of them. There are also 100 prisoners. Each prisoner has 50 chances to find the box with their …

Total answers: 2

Saving Data with Requests Library

Saving Data with Requests Library Question: Good night, i’m trying to download a excel table from a URL with Requests library, but when I try to save the data in tabular mode, i obtain all the info from the URL but in HTML/text code, and i don’t know how to obtain the table with the …

Total answers: 1

Python – Beautifulsoup – parse multiple span elements

Python – Beautifulsoup – parse multiple span elements Question: I am trying to extract title from ‘span’. Using the below code as an example, the output I am looking for is 6536 and 9319, which are part of ‘title’. Seen below: span aria-label="6536 users starred this repository" class="Counter js-social-count" data-plural-suffix="users starred this repository" data-singular-suffix="user starred …

Total answers: 1

How to type annotate a function with return "shape" based on input "shape"?

How to type annotate a function with return "shape" based on input "shape"? Question: The function below receives a instance of a type (e.g. int) and returns a instance of another type (e.g. str). But, it may receive list of the input type (list[int]), and returns a list of the output type in that case …

Total answers: 2

How to pass body into aiohttp get request?

How to pass body into aiohttp get request? Question: How do I pass a body into aiohttp’s get requests? The code I have below is what I want to run asynchronously but im not able to get the same response – using requests request_accounts = requests.get( "{hostname}/audit/events".format( hostname=settings.RM_BASE_URL ), json={ "type": { "id": 2 }, …

Total answers: 1

sqlalchemy.create_all() got an unexpected keyword argument 'app' error

sqlalchemy.create_all() got an unexpected keyword argument 'app' error Question: new to coding, ive been stuck with this problem for about 4 days now and i have no idea how to get around it, ill paste the coding below init.py from flask import Flask from flask_sqlalchemy import SQLAlchemy from os import path from flask_login import LoginManager …

Total answers: 1

How can I call a function from inside another class and use it in a new file?

How can I call a function from inside another class and use it in a new file? Question: I am trying to make it so I can call paddle_up and paddle_down in the second file but I can only get the function "move". class PaddleOne(Turtle): def __init__(self): super().__init__() self.segments = [0] self.head = self.segments[0] self.Paddle_One() …

Total answers: 2