0

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
asked Nov 8, 2017 at 5:45
6
  • 1
    Are you using Numpy / Pandas? Commented Nov 8, 2017 at 5:48
  • No, and I cannot as well. Commented Nov 8, 2017 at 5:50
  • 1
    We 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? Commented Nov 8, 2017 at 5:54
  • docs.python.org/3/tutorial/… Commented Nov 8, 2017 at 5:57
  • 1
    @YousufFarhan sounds like you want a dictionary Commented Nov 8, 2017 at 6:06

1 Answer 1

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']
answered Nov 8, 2017 at 6:10
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.