Questions tagged [list]

The list tag may refer to: a linked list (an ordered set of nodes, each referencing its successor), or a form of dynamic array. Not to be used for HTML lists, use [html-lists] instead.

list
Filter by
Sorted by
Tagged with
-10 votes
1 answer
6k views

How to generate a random word

I don't know how I would take a word from a list in Python 3.3. This is my current code: print(random.randstr("blue","red","green","yellow")) And I get this error: print(random.randstr("blue","red",...
user avatar
-11 votes
1 answer
154 views

Remove element from a Python list until found a specific character

Hello I have this Python List carachter = "@" list = ['Montpellier', 'Saint-Etienne', '@', 'Strasbourg', 'Reims', '@', 'PSG', 'Olympique Lyonnais', '21:05', 'SPAL', 'Sassuolo', '@', 'Genoa', '...
cloude's user avatar
  • 328
-11 votes
2 answers
559 views

return the list with strings with single occurrence [closed]

given list of strings, need to return the list with strings that have no duplication (single occurrence) using java (stream) I have tried using distinct but it wont get single accurances
Maor Shetrit's user avatar
-11 votes
1 answer
219 views

How to get the sum of the elements of a list? [closed]

How can I get the sum of the elements of a list? i.e, f = [1,8,3] sum(f)=12?
ysen07's user avatar
  • 7
-11 votes
2 answers
119 views

Eliminate nested empty lists from a list

I am new to Python and want to ask this question. I have a list that has many types inside it, like int, list, empty list, float, string and I want to create an option to remove any type according to ...
heyho's user avatar
  • 1
-11 votes
1 answer
75 views

How to replace a word found in a string with what is in the list in Python

My string is below: word = "Continue: Lifetime Benefits in Running, Volume 1, Issue 1, February 2018" My list is: italic_list = ['Continue', ': Lifetime Benefits in Running', ' February 2018'] I ...
Arbin Bulaybulay's user avatar
-11 votes
1 answer
234 views

Set operations without using data type Set() [duplicate]

Problem: Here's a list as an input [A,B,C,E] Output: [A,B] [A,C] [A,E] [B,C] [B,E] [C,E] Basically, I want to take the union of the list with itself. Here's the code: pageSet_list = ['A', 'B', '...
kshikhar's user avatar
  • 593
-12 votes
1 answer
837 views

Sum of Squares of List Elements [closed]

Write a function sum_of_squares(xs) that computes the sum of the squares of the numbers in the list xs. For example, sum_of_squares([2, 3, 4]) should return 4+9+16 which is 29:
Nate's user avatar
  • 33
-12 votes
3 answers
123 views

Error 1 ) expected for add a string in list [closed]

Why is this error? How to fix this error? The semicolons are wrong List<string> codeForPortal=new List<string>(); codeForPortal.Add("<script type="text/javascript" ...
Sun Rise's user avatar
-12 votes
1 answer
195 views

Can Someone Explain What Just Happened (Python) [closed]

I was working on my AI pathfinding(which you don't need to understand), for some reason, my On[3] list was expanding when I did this in the shell: tempList.append([On[1]-1]) (After the program messed ...
Larry McMuffin's user avatar
-13 votes
2 answers
119 views

how to convert list to dictionary? [closed]

I have this: l = ["a" ,"b" ,"c" ,"d" ,"e" ,"i" ,"i" ,"e"] and I want it like that and with quantity of every key: l = {"a":"1", "b":"1", "c":"1", "d":"1", "e":"2" ,"i":"2"}
TeviXor's user avatar
-13 votes
1 answer
135 views

How can i make a set in my list in python?

I need to make this [['#', '#', '#', '#', '#', '#', '#'], ['#', ' ', ' ', ' ', ' ', ' ', '#'], ['#', ' ', '$', '+', '$', ' ', '#'], ['#', '.', '*', '#', '*', '.', '#'], ['#', ' ', '$', '.', '$', ' ', ...
dsboy's user avatar
  • 7
-13 votes
1 answer
3k views

How can I create an empty 3d multidimensional array

This code is my attempt at creating an empty 3d array. n=3 board = [[[ 0 for _ in range(n)] for _ in range(n)] for _ in range(n)] print(board) So, what that creates is ...
Hamad Kashmiri's user avatar
-13 votes
1 answer
74 views

Compare in Python two lists and create a new one that is combinated [closed]

I have two lists that look like this : a = [{"service" : "yoga", "price": 30}, {"service": "golf", "price" : 40}] b = ["basketball", "yoga", "soccer", "golf"] I'd like to compare the list and return ...
Ragnar's user avatar
  • 3
-13 votes
2 answers
1k views

Check if there is a number near the same number in a list - python [duplicate]

I want to check if for example the int 2 comes after or before another 2: list = [2, 2, 3] if 2 and 2 in list: print "True" And if the list is this: list = [2, 3, 2] print "False" thx
Telep0rter's user avatar
-13 votes
5 answers
7k views

How to merge list of dictionaries in python in shortest and fastest way possible?

I want to merge list of dictionaries in python. The number of dictionaries contained inside the list is not fixed and the nested dictionaries are being merged on both same and different keys. The ...
user avatar
-13 votes
4 answers
287 views

Python 3: How to create a list to print its every element on a new line - without loops or sep = "\n"

Let's say I have a list 'mylist'. For example, I prepared it like this: mylist = ['AB', 'CD', 'EF'] I need to print out each element of 'mylist' on a new line. However, I am not allowed to use loops ...
user3245256's user avatar
  • 1,918
-14 votes
1 answer
116 views

How to change the value of a key in a nested dictionary in Python [closed]

{ {'city':1 ,'person':{'name': 'John', 'age': '27'}}, {'city':2 ,'person':{'name': 'Marie', 'age': '22'}}, {'city':3 ,'person':{'name': 'Luna', 'age': '24'}}, {'city':4 ,'person':{'name': 'Peter', ...
Barny's user avatar
  • 391
-15 votes
3 answers
180 views

I want to create a sorted list of nom duplicated

I need to create a sorted list with billions of elements and then create a second list without duplicate elements containing the first letter of each element of the first list and the position of this ...
Beto Silva's user avatar

1
2851 2852 2853 2854
2855