arraylist

pass only the print result in another function

pass only the print result in another function Question: I am practicing python functions tonight and I come over a problem. I was trying to make a reservations program and it did not seem to work. Here’s my code so far: def make_res(): res = [] answer = ‘y’ resnum = 0 while True: resnum …

Total answers: 1

change array consist of coordinate(x,y) to string

change array consist of coordinate(x,y) to string Question: i have path planning project with python and the result is array consist of coordinate(x,y) like this: [(0, 1), (1, 1), (2, 1), (3, 1), (4, 1), (5, 1), (5, 2), (5, 3)] since I want to send that data to arduino to control the movement of …

Total answers: 2

Calling a function for its side effects using a list comprehension

Calling a function for its side effects using a list comprehension Question: I wrote something like this: def fetch_data(stock_name: str): data = get_data(stock_name) # get the data using API print(data) target_list = ["TESLA", "APPLE", "GOOGLE"] [fetch_data(stock_name) for stock_name in target_list if len(stock_name) <= 5] Is it appropriate to use list comprehension and run the fetch_data …

Total answers: 1

Do different versions of python handle indexing differently?

Do different versions of python handle indexing differently? Question: python 3.10.4 Ubuntu 20.04 running python 3.10.4 spyder IDE Python 3.9.12 64-bit | Qt 5.9.7 | PyQt5 5.9.2 | Linux 5.15.0-47-generic My python version in ubuntu and spyder are different. Does this cause the following problems? I’ve run into two separate incidents on two separate sites …

Total answers: 1

Python: smallest number in list

Python: smallest number in list Question: I’m new to python and i don’t know how to find the smallest number in each array. The input is [ [2], [3, 4], [6, 5, 7], [4, 1, 8, 3] ] and the output should be [2, 3, 5, 1]. I have try this: x = [ [2], …

Total answers: 3

Rearrange the tuple by sorting in python

Rearrange the tuple by sorting in python Question: I have two lists. One list contains X coordinate values and second list contains Y coordinate values. Using these two lists, I want to make a tupple which is sorted by their first element. X coordinate = [2, 3, 4, 4, 3, 2, 1, 0, 0, 1, …

Total answers: 3

How to remove from these 2 lists of lists the possible lists that appear in both lists of lists?

How to remove from these 2 lists of lists the possible lists that appear in both lists of lists? Question: These are the two lists, both of which have the same number of elements: list1 = [[’23’, ’30’, ‘pm’], [’01’, ’00’, ‘am’], [‘1′, ’00’, ‘am’], [‘1′, ’00’, ‘pm’], [‘1’, ”, ‘pm’], [‘5’, ”, ‘pm’]] list2 …

Total answers: 2

Why does Python gives value error for below problem

Why does Python gives value error for below problem Question: Output screen: enter the number of elements:3 1 23 3 Traceback (most recent call last): File "<string>", line 18, in <module> ValueError: invalid literal for int() with base 10: ” > Code : arr =[] def runninsum(arr): srr = [] temp = 0 summ = …

Total answers: 2

Function of adding two lists in Python

Function of adding two lists in Python Question: whenever I run following code of adding two lists in python below mentioned error appears def add_lists(L1, L2): R = [] for i in range(0, len(L1)): R.append(L1[i]+L2[i]) return R L2 = [3, 3, 3, 3] L1 = [1, 2, 3, 4] add_lists(L1, L2) print("Resultant list of: ", …

Total answers: 3

Magical method __len__()

Magical method __len__() Question: How to call the __len__() function using an object of the class ? class foo(object): def __init__(self,data) self.data = data def __len__(self): return len(self.data) x = foo([1,2,3,4]) Asked By: VIMALAN S S || Source Answers: You can do it this way: >>>x = foo([1,2,3,4]) >>>len(x) 4 Answered By: Tugay Same way …

Total answers: 5