Skip to content
Fix Code Error

Tag: list

Function that replaces for loop counter Python

July 18, 2021 by Code Error

Posted By: Anonymous Is there a way of outputting the number of iterations without using the counter variable? values= ["4","a","rk","sp"] counter = 0 for k in values: print("counter: ",counter, "value: ", k) counter +=1 Solution enumerate would work well here: values= ["4","a","rk","sp"] for count, k in enumerate(values): print("counter: ", count, "value: ", k) The purpose …

Continue Reading

Get index of a list with tuples in which the first element of the tuple matches pattern

July 18, 2021 by Code Error

Posted By: Anonymous I have a list of tuples: countries = [(‘Netherlands’,’31’), (‘US’,’1′), (‘Brazil’,’55’), (‘Russia’,’7′)] Now, I want to find the index of the list, based on the first item in the tuple. I have tried countries.index(‘Brazil’), I would like the output to be 2. But instead, that returns a ValueError: ValueError: ‘Brazil’ is not …

Continue Reading

R Combining list from vectors

July 17, 2021 by Code Error

Posted By: Anonymous I am trying to combine two lists in R as follows c("a"="1","b"="2","c"="3") what gives me: a b c "1" "2" "3" I would like to obtain the same results using the following lists, letters <- c("t", "s", "k") numbers <- c("1", "2", "3") Is there some simple way to do so? Solution …

Continue Reading

List tile is not showing all data in flutter?

July 17, 2021 by Code Error

Posted By: Anonymous The full list is not showing and I’m not getting any error. I’m getting this output class _RandomWordsState extends State<RandomWords> { final List<String> _suggestions = [‘ Cleaning a’, ‘cleaning b’,’Cleaning c’,’Cleaning d’,’cleaning e’]; final _saved = <String>{}; final _biggerFont = TextStyle(fontSize: 18.0); Widget _buildSuggestions() { return ListView.builder( padding: EdgeInsets.all(16.0), itemCount: _suggestions.length, itemBuilder: …

Continue Reading

Unique headerValue and expandedValue for ExpansionPanelRadio

July 16, 2021 by Code Error

Posted By: Anonymous How to add unique value to each expandable tile to make the FAQ look like this? Took my code from this link: https://medium.com/aubergine-solutions/how-to-create-expansion-panel-list-in-flutter-2fba574366e8 I want to add my own unique headerValue and expandedValue and not let it just take up a standard number like headerValue: ‘Book $index’, expandedValue: ‘Details for Book $index …

Continue Reading

Add to List from XElement in foreach loop

July 15, 2021 by Code Error

Posted By: Anonymous Program.cs using ConsoleApp2.Models; using System.Collections.Generic; using System.Linq; using System.Xml.Linq; namespace ConsoleApp2 { class Program { static void Main(string[] args) { string City_Name = "GdaÅ„sk"; var doc = XElement.Load($"https://maps.googleapis.com/maps/api/place/textsearch/xml?key={key}&query=restaurants+in+{City_Name}&language=pl&fields=place_id"); List<PlaceIdModel> IdList = doc.Descendants("result").Select(n => new PlaceIdModel { PlaceId = n.Element("place_id").Value }).ToList(); List<PlaceDetailsModel> placeDetailsModel = new List<PlaceDetailsModel>(); foreach (var item in IdList) { var …

Continue Reading

I am trying to implement refreshCountryList , which should return countryList(array of objects) variable which contains all countries

July 15, 2021 by Code Error

Posted By: Anonymous Country.component.ts countryList :any; searchvalue : string = "" ; constructor( private service : SharedService) { } ngOnInit(): void { this.refreshCountryList(); } refreshCountryList(){ this.service.getCountryList().subscribe(data=>{ this.countryList = data console.log("countryList inside subscribe :",this.countryList ) ; }); console.log( "list outside subscribe :" , this.countryList); } shared.service.ts export class SharedService { readonly APIUrl = "https://localhost:44383/api/CountryApi/"; constructor(private http: …

Continue Reading

Using lapply to count values in a single column in multiple dataframes

July 15, 2021 by Code Error

Posted By: Anonymous I am trying to calculate the percent occurence of specific values in a single column of a dataframe. I use the following code to load a single dataframe, and calculate the total count of each value within the sinlge column "Counter". Then, I divide it by the number of rows present in …

Continue Reading

Using table on a list of arrays in R

July 14, 2021 by Code Error

Posted By: Anonymous Let’s say I have the following list in R: my_list <- list(structure(c(0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, -1, -1, -1, -1, 0), .Dim = c(1L, 25L)), structure(c(0, 1, -1, 0, 1, -1, 0, -1, -1, 1, 1, 1, …

Continue Reading

Prolog: a list of characters list of character list

July 14, 2021 by Code Error

Posted By: Anonymous I am implementing a words/2 predicate in which a list of characters can be rendered to a list of the character as a word inside a list. I use the mathematical symbol <=> to denote that they’re working in any mode. Please advise if there’s a better expression. The example: ?- words([p,r,o,l,o,g,’ …

Continue Reading

Dynamically Create a New Column in R

July 13, 2021 by Code Error

Posted By: Anonymous I am trying to improve my code and avoid repeating lines to import multiple csvs with same name structure: iOS_Weekly_Active_Users_20210301 <- read.csv("iOS_Weekly_Active_Users_20210301.csv", header = T) iOS_Weekly_Active_Users_20210301$WeekDate <- "2021-03-01" iOS_Weekly_Active_Users_20210308 <- read.csv("iOS_Weekly_Active_Users_20210308.csv", header = T) iOS_Weekly_Active_Users_20210308$WeekDate <- "2021-03-08" iOS_Weekly_Active_Users_20210315 <- read.csv("iOS_Weekly_Active_Users_20210315.csv", header = T) iOS_Weekly_Active_Users_20210315$WeekDate <- "2021-03-15" iOS_Weekly_Active_Users_20210322 <- read.csv("iOS_Weekly_Active_Users_20210322.csv", header = T) …

Continue Reading

Simple Syntax Question (tuple conversion)

July 13, 2021 by Code Error

Posted By: Anonymous I’m currently researching different ways to combine, organize and manipulate data for different purposes. Just today I found this zip() / iter() technique of creating a LIST containing TUPLES while also being able to specify how many elements are in each TUPLE. However, I’m unable to fully understand part of the syntax. …

Continue Reading

How to extract a sublist by the value of the first element from a nested list

July 13, 2021 by Code Error

Posted By: Anonymous I want to extract a sublist from a nested list based on the first element in each list. I have the following nested list: input = [ [‘nom’, ‘N’, ‘eye’], [‘acc’, ‘E’, ‘computer’], [‘dat’, ‘C’, ‘screen’] ] I want to have a function which returns [‘nom’, ‘N’, ‘eye’] when the first element …

Continue Reading

How to make pandas list without brackets between cells in python?

July 13, 2021 by Code Error

Posted By: Anonymous I have a list which I get from reading gsheet, it has all values in square brackets like this: [[‘example1’], [‘example2’], [‘example3’], [‘example4’], [‘example5’]] I would like to remove brackets from values for further steps and it should look like: [‘example1’, ‘example2’, ‘example3’, ‘example4’, ‘example5′] I’m stuck here for a while, any …

Continue Reading

How to change csv into dictionary

July 12, 2021 by Code Error

Posted By: Anonymous I have a csv file with columns as a list I want to turn into a dictionary with column headers as keys and the rest of the column as a list the value. I want to do it without importing. How would I turn this: [ [‘col1’, ‘col2’, ‘col3’, ‘col4’, ‘col5’], [‘1’, …

Continue Reading

Create NULL list of lists in R

July 12, 2021 by Code Error

Posted By: Anonymous I want to create a list (size 12) of lists (size 2) with NULL entries so I can fill them with the outcomes of a triple loop. I have tried something like pred_SAM: pred_SAM <- list(list(list()), list(list()), list(list()), list(list()), list(list()), list(list()), list(list()), list(list()), list(list()), list(list()), list(list()), list(list())) However I look for something …

Continue Reading

Exporting a list of dataframes as csv

July 12, 2021 by Code Error

Posted By: Anonymous I have a list of dataframes which I want to export as csv. I tried : for (i in listofdf){ write.csv(listofdf[i], file = paste(names(listofdf)[i],".csv", sep=""), row.names = FALSE) } and got : Error in listofdf[i] : invalid subscript type ‘list’. I read that I am feeding a list data type into a …

Continue Reading

How to convert list of strings to integer indexes?

July 12, 2021 by Code Error

Posted By: Anonymous I have a list like this: lst = [[‘ab’, ‘bc’, ‘cd’], [‘dg’, ‘ab’]] I want to build a string indexer and convert it into: lst_converted = [[1,2,3], [4,1]] Do some processing on the converted list and then if the output is [[3], [2]] lst_output = [[‘cd’], [‘ab’]] Here, ‘ab’ = 1 ‘bc’ …

Continue Reading

perform lookup on two lists and add element from second list to first list based on condition

July 12, 2021 by Code Error

Posted By: Anonymous I have two lists that I have looped over to match an element from the 1st list vals1 in the second one vals2. If the element indexed[0] from vals1 is present in vals2 index[0], I need to grad the element index[1] from vals2 and replace the element indexed[0] from vals1. If it …

Continue Reading

Flutter ListView changing values

July 12, 2021 by Code Error

Posted By: Anonymous I have a question: I have a ListView.builder in Flutter with Songs and every Song item has a Play Button on the left. So I click the play button the Icon changes and the song gets played. When I click another song in the list how can I set the Icon to …

Continue Reading

Sort list of strings considering two different criteria

July 12, 2021 by Code Error

Posted By: Anonymous I have the following list: l = [‘hey (0)’, ‘hey (1)’, ‘bye (3)’, ‘bye (1)’] And I want to sort it firstly by the numerical character and then alphabeticly The output should be: l = [‘hey (0)’,’bye (1)’, ‘hey (1)’, ‘bye (3)’] tried: l.sort(key = lambda x: (x[-2], x[1])) Any ideas? Solution …

Continue Reading

How to store class attribute information in a list when creating an object?

July 11, 2021 by Code Error

Posted By: Anonymous I am trying to find a way to store class attribute information in a list when the object is created. I am just learning python classes and am having some difficulty figuring out how to implement the str method correctly. muffins = [] class Muffin: def __init__(self,name,calories): self.name = name self.calories = …

Continue Reading

List Method in combination with initializing a new object

July 11, 2021 by Code Error

Posted By: Anonymous in my course i am actually at Lists and how to work with them. There is one command i dont fully get. I think the topic lists is pretty roff so please go easy on me. Person node = list.remove(0); Person is the Class node the new Oject What is inside of …

Continue Reading

I am trying to get output like below using pythone code…any suggestions?

July 11, 2021 by Code Error

Posted By: Anonymous I am trying to get output like below using pythone code…any suggestions? list=["ABCPMCABCCMD","CMDABC"] list2=["ABC","CMD"] output: [ABCABCCMD,CMDABC] Solution You can use re module: import re list1 = ["ABCPMCABCCMD", "CMDABC", "ABCMD"] list2 = ["ABC", "CMD"] r = re.compile("|".join(re.escape(w) for w in list2)) out = ["".join(r.findall(word)) for word in list1] print(out) Prints: [‘ABCABCCMD’, ‘CMDABC’, ‘ABC’] …

Continue Reading

How to add an additional space to the latter element in a list Python?

July 11, 2021 by Code Error

Posted By: Anonymous I have a list of strings and I hope to add an additional space to the latter element in it. my_list = [‘AA’, ‘BB’, ‘CC’, ‘DD’] my expected outputs: my_list = [‘AA’, ‘ BB’, ‘ CC’, ‘ DD’] I only know how to add space to each element using the code below: …

Continue Reading

How to print a ‘particular’ element in a list (not entire list), without brackets and quotes, while printing from class method?

July 11, 2021 by Code Error

Posted By: Anonymous I am trying to print a "particular" element from a list using below code. While printing the class instance variable self.Engine, the output [‘Merlin’] prints along with the quotes and brackets. How can I print simply the string, without quotes and brackets? Here is the code: class Rockets(object): Stages = "2 Stage" …

Continue Reading

How to collapse a data frame column of lists into one list for NLP

July 11, 2021 by Code Error

Posted By: Anonymous I am trying to do some topic analysis and I need to collapse a column in dataframe made up of lists, into one list of words. So here’s an approximation of what my data looks like: import pandas as pd d = {‘Case’: ["[wait, information, employer]","[case, assign, priority, level, 2, transmit]" ]} …

Continue Reading

Python: Convert 2d list to dictionary with indexes as values

July 11, 2021 by Code Error

Posted By: Anonymous I have a 2d list with arbitrary strings like this: lst = [[‘a’, ‘xyz’ , ‘tps’], [‘rtr’ , ‘xyz’]] I want to create a dictionary out of this: {‘a’: 0, ‘xyz’: 1, ‘tps’: 2, ‘rtr’: 3} How do I do this? This answer answers for 1D list for non-repeated values, but, I …

Continue Reading

Merge multiple JSON files outputs in one list object

July 10, 2021 by Code Error

Posted By: Anonymous I have a folder that contains many JSON files. I want to write Python code that scans all files, reads them, and merges them into a single list object. I tried the following. mypath = ‘C:/Users/data’ files = [‘f1.josn’, ‘f2.josn’, …, ‘f20.josn’] output_list = [] for file in files: with open(mypath+’/’+file, encoding=’utf-8′) …

Continue Reading

How to create a list of igraphs from ncol files?

July 10, 2021 by Code Error

Posted By: Anonymous I have a number of weighted graphs stored in *.ncol files. For the sake of the question lets say I have 2 files, ncol_1.ncol 21 53 1.0 5 52 1.0 32 52 1.0 119 119 0.5 119 85 0.5 87 0 1.0 36 116 1.0 85 87 1.0 116 5 1.0 4 …

Continue Reading

Posts navigation

  • 1
  • 2
  • 3
  • 4
  • …
  • 28
  • Next

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error