Questions tagged [list]

The term "list tag" can refer to two different concepts. Firstly, it could represent a linked list, which is a collection of nodes that are ordered and each node references its successor. Alternatively, it may indicate a type of dynamic array. However, please note that the term should not be utilized when referring to HTML lists; instead, you should employ the specific tag [html-lists].

Python: Array of Arrays

As a Python beginner, I am currently working on a project that involves a List of lists. My goal is to display specific lists by searching for one of their elements. In this particular case, the List contains user information such as name, username, age, ...

The Python error "List object is not callable" occurs when

import math def findBestLocation(lst): if len(lst) % 2 == 0: bestLoc = ((lst[len(lst)]//2) + (lst[len(lst)/2]-1)) // 2 else: bestLoc = lst(len(lst)//2) calculateDistanceSum(lst, bestLoc) return bestLoc def calculateDistanc ...

Generating a data set by combining various lists

Having just started with Python, I may be asking a basic question. I have two sets of lists, one containing volume names and associated counts. Here's a sample of the data: volumes1 = ['Shield', 'Side', 'expHall', &apos ...

Is List Comprehension Behavior Being Overloaded?

I have been given the task of designing a model representing cages filled with hardware. Each cage has N slots, with each slot potentially containing a card. To create this model, I plan to utilize a list where each index corresponds to a specific slot nu ...

Retrieving data from a collection in Python

data = ['random word1', 20, 'random word2', 54] data = list(map(list,zip(data[::2], data[1::2]))) print(data) [['random word1', 20], ['random word2', 54]] Now I am looking to extract values in a specific way: if ‘random word2’ in data: I want to ...

Decoding the data received from Firebase

Currently, I am utilizing c# to communicate with Firebase through the provided REST API. Upon sending a GET request to a specific node, the children are retrieved as anticipated. { "49d360b0-b3a8-4240-bd69-1f91b07365fd" : { "id" : "49d360b0-b ...

Separating email addresses from a list of emails in Python: Splitting them based on commas and spaces

My input is email_list = "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d9b4b8b0b5e899b4b8b0b5f7bab6b4">[email protected]</a>,<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f598949c99c ...

How can I retrieve a particular key value from a dictionary?

I'm working with a dictionary that looks like this: d = {'k1':[0.2,0.65,0.23], 'k2':[0.32,1.2,3.3], 'k3':[1.8,0.6,0.4], ...} My goal is to create a list containing the key along with the second value of each key. I atte ...

Remove an element from a Python list using a predefined value

Is there a method to remove an element from a list with a default value if the index is not found? While Python dictionaries have the pop function that can return a default value, like in the example below: d = {"stack": "overflow"} d.pop("stack", 10) # re ...

Remove an additional bracket from a given list

I am working with a list in Python that looks like this: results = [[['New','York','intrepid', 'bumbling']], [['duo', 'deliver', 'good', 'one']]] My goal is to transform it i ...

Retrieve a section of a JSON file in Python and save it into a new JSON file

I need to filter out specific data from a JSON file using a predefined list of keys and save it as a new JSON file. For example: { "211": { "year": "2020", "field": "chemistry" }, " ...

Tips for saving the names of all mp4 files into an array

Currently, I am facing an issue while trying to move a file from another directory to the current directory. Moving a file from the current directory to another works fine for me. However, when attempting to move a file in the opposite direction, I encount ...

Manipulating dictionaries within a list in Python

Recently, I have encountered an issue with a personal script that I developed, which involves using dictionaries to achieve a specific structure. The initial structure looks like this: [ {'airfare': 1000, 'place': 'nameOfPlace&ap ...

What is the process for estimating based on the departure time and arrival time from previous and subsequent trips?

https://i.stack.imgur.com/pHSkx.png I'm currently faced with a challenge involving a list of arrival and departure timings. Let's say in the image provided, when i = 3 and i = 4 have a departure time of 0. What I aim to accomplish is to utilize the depart ...

Is there a method to merge elements from two separate "lists of lists" that contain the same elements but have different lengths within each list?

In an attempt to merge two distinct lists of lists based on shared elements, I find myself faced with a challenge. Consider the following: list1 = [['a1', 'a2', 'b2'], ['h1', 'h2'], ['c1', ' ...

What are the various techniques available to insert an item into a list, and which one offers the quickest performance?

During a recent job interview, I was asked about Python: "How many methods are available to add an element to a list and which one is the most efficient?" I mentioned using the list's built-in methods like append, insert, and the use of the + operator. Ar ...

Obtaining particular elements within Lists that are nested

Hello, I am a beginner learning Python and programming in general. Please forgive me if my approach is not the most efficient. Let's say I have a list: Coordinates = [[1, 1], [2, 1], [1, 2], [1, 1]] And now I want to create a new list called xCoordinate ...

Locating specific phrases within a vast text document using Python

The code below represents the program I have written: with open("WinUpdates.txt") as f: data=[] for elem in f: data.append(elem) with open("checked.txt", "w") as f: check=True for item in data: if "KB2982791" in item: ...

De-duplicate values within multiple JSON lists using Python

Despite the abundance of questions regarding duplicates, I am struggling to find a suitable solution for my specific case. My JSON structure looks like this: { "test": [ { "name2": [ "Tik", "eev ...

Tips for making a Python list without utilizing the range function in For Loops

If we take the string myString = "ORANGE" How can we implement a loop that displays each character with its position as shown below? 1O 2R 3A 4N 5G 6E I'm facing some confusion on how to achieve this without utilizing range. ...

Converting JSON arrays into Python lists

I am encountering difficulties in parsing a JSON array I created into a Python list. Despite my efforts, I have not been successful in achieving this. Is there a way to convert my JSON array into a Python list? The structure of the json data I want to pa ...

Tips on divvying up a dataframe into several different dataframes, using special characters like ' . ' and ' - '

My goal is to divide my data into several different dataframes. I encountered an issue where Python does not recognize domains like '.com', '.us', '.de', '.in' when trying to do so. Any suggestions on how to overcome this? I attempted to convert a group ...

Looking for a list that you can edit with CSS styling?

I'm struggling to create a flexible list that can be easily modified. My goal is to have an ordered list with unique labels such as 1,2,3,4,5,6,7,8,9,0,A,B,!,# Although I've managed to number the list items, I am stuck on adding the extra labels. Here's ...

Python's CSV writer puts quotation marks around values to ensure that the data is properly enclosed and doesn

Is there a way to save a list in a csv file without the values becoming strings upon reloading it? Upon executing my code and checking the content of the file using "cat", the output shows: cat test.csv -> "[1, 2]","[3, 4]","[5, 3]" This is the code ...

Converting a flattened column of type series or list to a dataframe

I am looking to extract specific data from my initial dataset which is structured as shown below: time info bis as go 01:20 {'direction': 'north', abc {'a':12,'b':20 } yes ...

Tips on analyzing two lists that have unique identifiers yet contain identical information

I am dealing with 2 lists that have the same content but reference different names. There is a table I can download with an 'Export' button, which saves a CSV file to my local system. I am using Selenium to retrieve the table data and I have att ...

Guide to creating a symmetrical grid pattern using python (with sample illustration)

lst = ['40', '36', '112', 'Eric', '30', 'Bob', '15', '125', '45', 'Philippe'] d = [] things = 0 summ = 0 for val in lst: try: summ+= float(val) ...

Combine lists with Python's intercalate function

def interleave_lists(list1, list2): l1 = ["b", "d", "f", "h"] l2 = ["a", "c", "e", "g"] assert interleave_lists(l1,l2) == ['a', 'b', 'c', 'd', 'e','f', 'g', 'h'] assert l1 == ["b", "d", "f", "h"] assert l2 == ["a", "c", "e", "g"] I am ...

Performing iteration over a list of elements using Java Selenium by targeting

I attempted to iterate through a list on a website. The separate line ID is as follows: //*[@id="lista-wiersz-74813704"] The number varies, so I believe I cannot use it. A different web element is: <li id="lista-wiersz-74779144" class = "linkDoKart ...

retaining the last element from a list when returning it in a function to avoid receiving None

Is there a way to output all elements of a list? def print_all(list): for i in range(len(list)): print(i) a = print_all(list) print(a) When using print(i), I get 'None' as the final value. Using return only outputs the first value. ...

Looking for assistance with aligning UL elements in CSS using absolute positioning for a dropdown effect

I'm currently working on implementing a language switching feature on this website. The concept involves using a SPAN element that reveals a dropdown box (based on UL) containing a list of available languages when hovered over. Below is a preview of t ...

The total squared difference calculated for a collection of lists containing individual lists

Looking for a way to calculate the sum of squared differences between two lists? Here's what I have: list = [[20.20458675 17.14946271 2.78568516 5.8363439 14.00318441 11.96825089] [ 3.89675236 9.99523907 13.0328716 18.10551237 22.11318234 -0.30 ...

The type '_InternalLinkedHashMap<String, dynamic>' is incompatible with the type 'BanarModel'

There seems to be an issue with the code. I believe it is because I stored an object in a list, so how can I solve this? The error message says '_InternalLinkedHashMap' is not a subtype of type 'BanarModel'. class Home ...

Explore a directory by keyword to attach specific items from the list

Scenario After scraping a list of links from a specific site, I encountered the following format: ['https://twitter.com/ONS', 'https://www.ons.gov.uk/file?uri=%2feconomy%2feconomicoutputandproductivity%2foutput%2fdatasets%2feconomicactivityfasterindicato ...

An application designed to generate a compilation of multiple documents

Data files: file.json - database of athletes including chest number, first name, and last name result.txt - initial results with time data in specific format Information to be included in the list: Results Summary Position | Chest Number | First Na ...

Discover the least common multiple for a maximum of 5 numerical values

Struggling to create a program that can compute the least common multiple of up to five numbers. The current code I have looks like this: a = b = True while a == True: x = input(' Enter two to five numbers separated by commas: ').split(',') if ...

Discovering the minimum and maximum values defined by the user in a list of tuples

I am currently working with a collection of tuples, each containing 2 integers: data_list=[(20, 1), (16, 0), (21, 0), (20, 0), (24, 0), (25, 1)] My goal is to identify and retrieve the tuple that has the smallest second integer value but the largest firs ...

Python 3.5 Custom Compare Sorting Issue: Unexpected Results

I am currently working on creating a custom sorting method for a list of strings representing playing cards. The list consists of card values in the format: ['d10', 's2', 'c3', 'b5', 'c7', 'b2', 'b10', 'b7', 'c6', 's6'] Each string includes a character ( ...

List of tuples indicating the index of tuples that are incomplete

Issue at hand: I currently possess a series of tuples (a,b,c) and I am seeking to locate the index of the first tuple commencing with specified 'a' and 'b'. For instance: list = [(1,2,3), (3,4,5), (5,6,7)] In this case, if a = 1 and ...

Having an issue with Material-UI: ListItem onClick function not triggering

Currently, I am working on a project using React and Material-UI. The main goal is to display a list and trigger a function when an item in the list is clicked. However, for some reason, the onClick function doesn't seem to be called. Can you help me ...

Python error message: "Invalid index. List indices must be integers, not tuples."

I have been assembling a robot that navigates around a 2D grid room of 8 x 8 dimensions. One crucial step is configuring the sensors to detect information from the closest 5 tiles surrounding the robot. self.sensors = [0 for x in xrange(5)] In this insta ...

Converting a document into an ASCII encryption key

I am attempting to encode a user input file using a random ascii key. I have managed to generate the random key and convert the file contents into ascii, but I am struggling with how to apply the key for encryption. I have tried several approaches, but my ...

Is there a way to extract a specific set of numbers from a string?

For the following data: [‘23 2312 dfr tr 133’, ‘2344 fdeed’, ‘der3212fr342 96’] I am seeking a function that can extract values containing a specific number of consecutive numbers. The presence of spaces or other text between the numbers is ...

matching lists and dictionaries in Python

I am seeking the sentence that includes specific words from a list and a dictionary I have. mykeys=['city', 'salon', 'last', 'website', 'car', 'offense', 'open', 'day', ' ...

Using Python regular expressions to extract strings that are numeric values between 0 and 9,999,999.99, regardless of whether they contain no commas or multiple commas

I'm seeking a method to extract this specific string from a CSV list. I suspect that the commas are causing some issues, but I'm not entirely sure. The number at the end can range from 0 to 9,999,999.00 and may contain zero commas or multiple. Transfer Out ...

Accessing dropdown selection in Javascript-Json: A Comprehensive Guide

My dropdown list is being populated dynamically using json. The selected option from the first dropdown determines the options in a secondary dropdown. I need to use the selection from the second dropdown to automatically fill out two more fields. For exa ...

Can Selenium provide me with a numerical value?

I recently started using Selenium and I've encountered a problem. The solution is probably simple, but I haven't been able to find it anywhere. When I attempt to locate an element with the code below: options = Options() options.binary_location="C:P ...

What is the best way to format a list for writing into a file?

I am working with a Python list and I want to format it in a specific way. Input: trend_end= ['skill1',10,0,13,'skill2',6,1,0,'skill3',5,8,9,'skill4',9,0,1] I need the file to look like this: Output: 1 2 3 1 ...

Analyzing the values of various keys within a dictionary for comparison

My data structure involves dictionaries nested inside a list, represented as follows: sample_dict = [{1: [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]]}, ...

What is the most effective method for comparing and updating objects within arrays or lists in frontend Angular applications using TypeScript?

While I acknowledge that this approach may be effective, I am of the opinion that there exists a superior method to accomplish the same goal I have two separate lists/arrays containing distinct objects, each with a common attribute. My objective is to ite ...

Python guide to cycling through a list and merging certain elements?

Consider a scenario where we have a specific list l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, ...]. The objective is to group elements from this list as follows: (1, 5, 9) (2, 6, 10) (3, 7, 11) (4, 8, 12) This grouping pattern should continue considering ...

Error encountered when attempting to add a new key to a dictionary using index numbers for iteration, resulting in the list index being out of

Avoiding too many tedious details about the origin, the myquery function executes a script that retrieves information from my work database. This information is then organized into a list. The objective is to transfer this data line by line into a Google S ...

Python may not always accurately detect function loop conditions

I have the following Python code snippet: def numTest(): getNum = "https://sms-activate.ru/stubs/handler_api.php?api_key=" + api + "&action=getNumber&service=go&country=3" numReq = requests.get(getNum) smsNum = n ...

Struggling with the elimination of bullet points in CSS navigation bars

I'm having trouble removing the bullet points from my navigation bar. I've tried using list-style-type: none and even adding !important, but it doesn't seem to work. Strangely enough, everything looks fine in Chrome, but I get an error when viewing in Fire ...

sophisticated technique for calculating the product of all whole numbers within a dictionary of lists

I have a dictionary containing strings that correspond to lists of integers. My goal is to multiply each integer in every list by a specific value. What is the most efficient and elegant approach to achieve this task? The following code snippets do not yi ...

Substitute operation within a collection of text elements

I am trying to loop through a list of strings and replace any occurrence of a specific character, like '1', with a word. However, I'm puzzled as to why my current code is not working. for x in list_of_strings: x.replace('1', 'Ace') Just a heads up, t ...

What is the best way to extract strings from a list based on an integer value?

How can I extract specific strings from a list using integers? I attempted the following method, but encountered an error: list = ['1', '2', '3', '4'] listlength = (len(list) + 1) int1 = 1 int2 = 1 while (int1 < listlength): int2 = list[int1] ...

NLTK - A dive into stopwords and hashing on a list

Trying to simplify this problem as much as possible because I know how frustrating long and complex issues can be. I have a collection of tweets stored in a variable called 'all_tweets'. Some tweets are in the 'text' category while others are in 'extended ...

The Material UI list element fails to appear on the screen

I am encountering an issue where I am trying to display a Material UI list within a drop-down menu (using the Material UI drawer component) for mobile view, but the actual list is not appearing as expected. The code snippet for the list is as follows: con ...

The menu will expand to full width, with each list item evenly sharing the width to achieve full coverage

I am currently facing an issue with my horizontal menu on my website. I want the menu to stretch across the full width of the site, but I can't seem to get it right. Here is the code for my menu: <nav> <ul id="menu" class="menu"> <li& ...

A function designed to retrieve all nearby values within a list

After spending quite some time trying to tackle the problem at hand, I find myself stuck. I am dealing with a list of various values, such as: list1 = (17208, 17206, 17203, 17207, 17727, 750, 900, 905) I am looking to create a function that can identify a ...

Checking for the presence of elements from a list in a set using Pythonic methods

Looking for a solution to analyze the following: approved_countries = ['Germany', 'France'] We have 5 groups : {'Germany'} {'Germany', 'France'} {'Germany', 'France'} {'Germany&apo ...

Using AJAX in TYPO3's TCA forms to create dynamic dropdown menus

I have created two drop down lists in my TCA forms. The first one is called Campus and the second one is called Department. I want the options in the Department list to change based on the selection made in the Campus list. Essentially, the items in the De ...

What is the best way to generate a Python list of size L filled with random numbers between 1 and N?

If I use the getList(10,6) function, will the list contain 10 numbers ranging from 1 to 6 with possible repeats? For instance, [1,4,2,6,3,8,5,5,2,1] Should I simply generate random numbers using randrange and keep appending them, or is there a more effici ...

struggling with setting up a Python script to automate logging into several email accounts

Here is my code where I am attempting to create a function that includes a list to log into each email account one at a time. The issue I am facing is that it is trying to loop through the entire list instead of logging into one email at a time. How can I ...

Developing a tic tac toe software application

game_grid = [1, 2, 3, 4, 5, 6, 7, 8, 9] row1 = [1, 2, 3] row2 = [4, 5, 6] row3 = [7, 8, 9] game_grid = [row1, row2, row3] separator = 10*'-' print(game_grid [0][0],'|',game_grid [0][1],'|',game_grid [0][2]) print(separator) print(game_grid [1][0],'|',game ...

Having trouble removing the last 4 values from a list in Python, they are not being removed as expected

After updating the guest list and inviting everyone, I realized that I could only accommodate two people for dinner. guests = ['Abbas', 'Rafy', "sherry"] for i in range(0,3): print("Hi, I am inviting you to d ...

Converting multi-dimensional arrays into Pandas data frame columns

Working with a multi-dimensional array, I need to add it as a new column in a DataFrame. import pandas as pd import numpy as np x = np.array([[1, 2, 3], [4, 5, 6]], np.int32) df = pd.DataFrame(['A', 'B'], columns=['First']) Initial DataFrame: First ...

Changing the names of duplicated tuples in a Python list

If there is a list of tuples: [("heat", 200), ("time", "15:00"), ("time", "16:00")] What is the method to achieve the following result by renaming duplicate keys in tuples. [("heat", 200), (" ...

Is there a method to calculate the total of sequential identical items within a list?

I need help finding a more efficient way to calculate the sum of consecutive similar items in a list. My current code is not producing the expected last result. Any suggestions? [Code] lst=['+1', '-1', '-1', '-1', & ...

Condense dictionaries within a list of dictionaries in Python

I have a set of dictionaries that may vary in size. Each dictionary contains unique keys, but the same key can be found in multiple dictionaries. Values are unique across all dictionaries. My goal is to condense these dictionaries to include only the key- ...

Understanding the process of extracting elements from a list in Python

I extracted some data from a function and now I'm trying to extract specific information like the shape, labels, and domain from this output. [Annotation(shape=Rectangle(x=0.0, y=0.0, width=1.0, height=1.0), labels=[ScoredLabel(62282a1dc79ed6743e731b36, na ...

Adding JSON Objects in Python

In Python 3.8, I have successfully loaded two JSON files and now need to merge them based on a specific condition. Obj1 = [{'account': '223', 'colr': '#555555', 'hash': True}, {'account': ...

Choosing a clickable date from a calendar in Selenium using Java with two dates displayed

While attempting to select the 29th of February on a bootstrap calendar, I encountered an issue where the debugger tried to select the 29th of January, which was disabled or inactive. This led to a response indicating that the element was not clickable. T ...

Generate a list of unique combinations from a list of lists where all elements are distinct

For instance: [[3, 4], [2, 5], [6]] Will result in: [[3, 2, 6], [3, 5, 6], [4, 2, 6], [4, 5, 6]] Absence of lists with duplicate elements is required: e.g. [3, 3, 1, 5] I attempted to utilize itertools.product(*list) for generating all possible combin ...