Hi. First, I’m trying to get a good understanding of the syntax for .append and the correct indexing when slicing data sets. Second, I’d like to see if I can use that to eliminate a couple lines of code and/or making a new variable. I commented out the bits I’m looking at.
Here’s a data sample and the python I’m poking at.
apps_data = [['id', 'track_name', 'size_bytes', 'currency', 'price', 'rating_count_tot', 'rating_count_ver', 'user_rating', 'user_rating_ver', 'ver', 'cont_rating', 'prime_genre', 'sup_devices.num', 'ipadSc_urls.num', 'lang.num', 'vpp_lic'],
['284882215', 'Facebook', '389879808', 'USD', '0.0', '2974676', '212', '3.5', '3.5', '95.0', '4+', 'Social Networking', '37', '1', '29', '1'],
['389801252', 'Instagram', '113954816', 'USD', '0.0', '2161558', '1289', '4.5', '4.0', '10.23', '12+', 'Photo & Video', '37', '0', '29', '1'],
['529479190', 'Clash of Clans', '116476928', 'USD', '0.0', '2130805', '579', '4.5', '4.5', '9.24.12', '9+', 'Games', '38', '5', '18', '1'],
['420009108', 'Temple Run', '65921024', 'USD', '0.0', '1724546', '3842', '4.5', '4.0', '1.6.2', '9+', 'Games', '40', '5', '1', '1'],
['284035177', 'Pandora - Music & Radio', '130242560', 'USD', '0.0', '1126879', '3594', '4.0', '4.5', '8.4.1', '12+', 'Music', '37', '4', '1', '1']]
titles_data = [title[1] for title in apps_data[1:5]]
print(titles_data)
reversed_titles_data = []
for element in range(len(titles_data)):
reversed_titles_data.append(titles_data[-element -1]) # First, what is the format for (titles_data[this_part and_this_part])? Where can I look up the documentation?
print(reversed_titles_data)
# Second, is there a way to make someting like this work? To avoid creating a new variable...
# other_reversed_titles_data = []
# for element in range(len(apps_data)):
# other_reversed_titles_data.append(apps_data[-element -1])
# print(other_reversed_titles_data)
The second loop produces all the data in reverse, not just the titles.
Thanks so much. Any insight is appreciated!