iterable

Associate iterables and items from a list in a for loop

Associate iterables and items from a list in a for loop Question: Is it possible to associate certain iterables in a loop with certain items from a list ? I have two lists to start with (totalpages and arguments) and I need to build up certain URL’s. totalpages = [300, 0] arguments = [‘argument1’, ‘argument2’] …

Total answers: 3

How to index a json key array that sometimes only has one element, and is no longer an iterable?

How to index a json key array that sometimes only has one element, and is no longer an iterable? Question: I’m new to json, and I’m having trouble dealing with indexing keys that usually have sub-array but sometimes they don’t. Usually, key2 and key3 contain sub-array: json_obj = json.loads(x) json_obj["key1"]["key2"][idx]["key3"][idx]["key4"] However, sometimes key2 and/or key3 …

Total answers: 1

can only join an iterable error on shell scrapy on python scraping

can only join an iterable error on shell scrapy on python scraping Question: I have a simply code for scrapy but i got an error when there is None, see my code below, how can fix it In [428]: ”.join(response.css(".prdd-price-first::text").get()).strip() TypeError: can only join an iterable Asked By: crawlers || Source Answers: Iterable means your …

Total answers: 1

Find palindrome python space complexity?

Find palindrome python space complexity? Question: Given the following code in python which checks whether an string of n size is palindromic: def is_palindromic(s): return all(s[i] == s[~i] for i in range(len(s) // 2)) What is the space complexity of this code? Is it O(1) or O(n)? The all function gets an iterable as a …

Total answers: 2

Python – How to avoid refer multiple names to one dict

Python – How to avoid refer multiple names to one dict Question: I am struggling with python dictionary. I have two dics named defaultSettings and personalSettings. I want to make function sets personalSettings‘s values to defaultSettings‘s values. But I don’t want to all changes be applied to defaulSettings. I tried this code: defaultSettings = {‘s1’: …

Total answers: 2

How to modify list elements while iterating over the list?

How to modify list elements while iterating over the list? Question: In Python it is not possible to modify a list while iterating over it. For example, below I cannot modify list_1 and the result of the print will be [0, 1, 2, 3, 4]. In the second case, I loop over a list of …

Total answers: 1

Encoded Table from all combinations of a list

Encoded Table from all combinations of a list Question: I’ve spent a little while on this and got an answer but seems a little convoluted so curious if people have a better solution. Given a list I want a table indicating all the possible combinations between the elements. sample_list = [‘a’, ‘b’, ‘c’, ‘d’] (pd.concat( …

Total answers: 1

How to iterate through objects in a class?

How to iterate through objects in a class? Question: For a script I’m writing I would like to be able to something like this. class foo: __init__(self): self.a = ‘path1′ self.b = f'{self.a}path2′ bar = foo() for i in bar: if not os.path.isdir(i): os.mkdir(i) But I can’t quite figure out how to make the class …

Total answers: 2