I have created a list which has the totality of all the data in the csv file.
How do I seperately call upon data in rows and columns?
For instance:
**a, b ,c**
**1** a1 b1 c1
**2** a2 b2 c2
How can I identify a single cell within the list?
OneCricketeer
193k20 gold badges147 silver badges277 bronze badges
-
1Are you using Numpy / Pandas?OneCricketeer– OneCricketeer2017年11月08日 05:48:56 +00:00Commented Nov 8, 2017 at 5:48
-
No, and I cannot as well.Yousuf Farhan– Yousuf Farhan2017年11月08日 05:50:09 +00:00Commented Nov 8, 2017 at 5:50
-
1We don't know how your data looks. You say you have it in a list, is this a list for each row? Can you post an example?Kind Stranger– Kind Stranger2017年11月08日 05:54:49 +00:00Commented Nov 8, 2017 at 5:54
-
docs.python.org/3/tutorial/…Jack Homan– Jack Homan2017年11月08日 05:57:15 +00:00Commented Nov 8, 2017 at 5:57
-
1@YousufFarhan sounds like you want a dictionaryKind Stranger– Kind Stranger2017年11月08日 06:06:58 +00:00Commented Nov 8, 2017 at 6:06
1 Answer 1
try below code:
l = ['a', 'b', 'c','1','a1', 'b1', 'c1', '2', 'a2', 'b2','c2']
columns = 3
result = list(zip(*[iter(l[columns:])]*(columns+1)))
result2 = {i[0]:i[1:] for i in result}
item_id = '2'
result2[item_id]
output:
('a2', 'b2', 'c2')
or you could try below code:
l = ['a', 'b', 'c','1','a1', 'b1', 'c1', '2', 'a2', 'b2','c2']
columns = 3
item_id = '2'
index = l.index(item_id)
l[index:index+columns]
output:
['a2', 'b2', 'c2']
Sign up to request clarification or add additional context in comments.
Comments
lang-py