sublist

Substitution of values from one list with corresponding index from another

Substitution of values from one list with corresponding index from another Question: I need a little bit of help. I’m stuck on how to approach this one. So the general idea is to have a function taking 3 inputs. First is a list, second is also a list, but it contains values which are considered …

Total answers: 1

How do i split a list and and turn it into two dimensional list?

How do i split a list and and turn it into two dimensional list? Question: I have a list: lst = [1,2,3,4,’-‘,5,6,7,’-‘,8,9,10] that needs to be split when the ‘-‘ character is encountered. and turned into a two dimensional list like so: [[1,2,3,4],[5,6,7],[8,9,10]] I have this so far and all it does is take the …

Total answers: 2

Get first element of sublist as dictionary key in python

Get first element of sublist as dictionary key in python Question: I looked but i didn’t found the answer (and I’m pretty new to python). The question is pretty simple. I have a list made of sublists: ll [[1,2,3], [4,5,6], [7,8,9]] What I’m trying to do is to create a dictionary that has as key …

Total answers: 5

sublist to dictionary

sublist to dictionary Question: So I have: a = [[“Hello”, “Bye”], [“Morning”, “Night”], [“Cat”, “Dog”]] And I want to convert it to a dictionary. I tried using: i = iter(a) b = dict(zip(a[0::2], a[1::2])) But it gave me an error: TypeError: unhashable type: ‘list’ Asked By: user2240542 || Source Answers: Simply: >>> a = [[“Hello”, …

Total answers: 2

How to process a string into layer of sublists?

How to process a string into layer of sublists? Question: This is the example form, I’ll try to explain it in words later. I have a list from breaking up a string… say [a, a, a, b, a, a, b, a, c, a, b, a, a, c, a, c, a] where b is criteria 1 …

Total answers: 7