<jupyter_start><jupyter_text>What is the most popular trip? I would not use the word 'compare' I would say 'combine', lets say you have 10 stations (stations 1 through 10) a trip is a combination of 2 stations.  So from "Station 3 to Station 5" is a "trip", I can create a tuple for that: ('Station 3', 'Station 5') and I can use that tuple as a dictionary key, and I can count (increment the dictionary element with this key) every time this trip shows up in my data (or add it to my dictionary the first time I encounter it) as I'm inspecting each row.<jupyter_code>#one
import csv
from pprint import pprint
import calendar
from collections import Counter

"""This takes the file and returns dict of values. """
with open('chicago.csv', newline='') as csv_file:
    reader = [{key: value for key, value in row.items()}      #list comprehimsion or one liners  {} its s dictionary
    	for row in csv.DictReader(csv_file, skipinitialspace=True)]
    
"""creates a mini chicogo file called testing"""
testing=(reader[0:15])
pprint(testing[0:1])<jupyter_output>[{'Birth Year': '',
  'End Station': 'Canal St & Monroe St (*)',
  'End Time': '2017-01-01 00:06:32',
  'Gender': '',
  'Start Station': 'Canal St & Taylor St',
  'Start Time': '2017-01-01 00:00:36',
  'Trip Duration': '356',
  'User Type': 'Customer'}]<jupyter_text>3.6.3 |Anaconda custom (64-bit)| (default, Oct 15 2017, 03:27:45) [MSC v.1900 64 bit (AMD64)]<jupyter_code>from collections import Counter

"""start/end station popular"""
station_start = []
station_end = []
for x in testing:
    station_start.append(x['Start Station'])
    station_end.append(x['End Station'])

y=Counter(station_start)
d= max(y,key=y.get)

z=Counter(station_end)
e= max(z,key=z.get)
print('popular start station is {} and popular end station is {}'.format(d,e) )
print(testing[1])<jupyter_output>{'Start Time': '2017-01-01 00:02:54', 'End Time': '2017-01-01 00:08:21', 'Trip Duration': '327', 'Start Station': 'Larrabee St & Menomonee St', 'End Station': 'Sheffield Ave & Kingsbury St', 'User Type': 'Subscriber', 'Gender': 'Male', 'Birth Year': '1984.0'}<jupyter_text>basically creating a list of dict of tuples and counting it  why not use list of dicts if list?Advantages of Tuple over ListSince, tuples are quite similiar to lists, both of them are used in similar situations as well.However, there are certain advantages of implementing a tuple over a list. Below listed are some of the main advantages:We generally use tuple for heterogeneous (different) datatypes and list for homogeneous (similar) datatypes.Since tuple are immutable, iterating through tuple is faster than with list. So there is a slight performance boost.Tuples that contain immutable elements can be used as key for a dictionary. With list, this is not possible.If you have data that doesn't change, implementing it as tuple will guarantee that it remains write-protected.<jupyter_code>"""trying to make a list of tuples"""
popular_trip = ()
for x in testing:
    popular_trip.append(x['Start Station'], x['End Station'])
print(popular_trip)<jupyter_output><empty_output><jupyter_text>because tuple is immutable i cannot append it.<jupyter_code>"""trying to make something to pull out data"""
popular_trip = []
for x in testing:
    popular_trip.append(x['Start Station'], x['End Station'])
print(popular_trip)<jupyter_output><empty_output><jupyter_text>tuples exercise [here](https://www.programiz.com/python-programming/tuple)<jupyter_code>"""still trying"""
from pprint import pprint
for x in testing:
    pprint (x['Start Station']x['End Station'])

"""trying to print out start end stations but alignment problem"""
from pprint import pprint
for x in testing:
    a=x['Start Station']
    b=x['End Station']
    print ('{}                             {}'.format(a,b))
#     print (x['End Station'])<jupyter_output>Canal St & Taylor St                             Canal St & Monroe St (*)
Larrabee St & Menomonee St                             Sheffield Ave & Kingsbury St
Orleans St & Chestnut St (NEXT Apts)                             Ashland Ave & Blackhawk St
Franklin St & Monroe St                             Clinton St & Tilden St
Broadway & Barry Ave                             Sedgwick St & North Ave
State St & Kinzie St                             Wells St & Polk St
Wabash Ave & Wacker Pl                             Clinton St & Tilden St
Daley Center Plaza                             Canal St & Monroe St (*)
Daley Center Plaza                             Canal St & Monroe St (*)
Dayton St & North Ave                             Ogden Ave & Chicago Ave
Wilton Ave & Diversey Pkwy                             Halsted St & Wrightwood Ave
Canal St & Madison St                             LaSalle St & Illinois St
Theater on the Lake                             Lakeview Ave & Fullerton Pkwy
Halste[...]<jupyter_text>solution [1](https://stackoverflow.com/questions/12091687/loop-print-through-two-lists-to-get-two-columns-with-fixedcustom-set-space-bet)    [2]( https://stackoverflow.com/questions/27663924/printing-2-evenly-populated-lists-side-by-side-evenly)<jupyter_code>"""printing 2 columns failed again"""
for x in testing:
    print(x['Start Station'])
    for y in testing:
        print(y['End Station'])
"""Failed again code wenr wrong"""
popular_trip = ()
for x in testing:
    popular_trip =(x['Start Station'], x['End Station'])
print(popular_trip[0])
"""Failed again code wenr wrong"""

popular_trip = ()
for x in testing:
    popular_trip += zip(x['Start Station'], x['End Station'])
print(popular_trip[0])
from collections import Counter
popular_trip = []   #change to () and see the diff
for x in testing:
    popular_trip += [[x['Start Station'], x['End Station']]]
print(popular_trip)
type(popular_trip)

"""gives long list of answers lenghtly"""
#https://stackoverflow.com/questions/49145315/how-to-count-the-occurance-of-multidimentional-arrays-of-string?noredirect=1#comment85295624_49145315
for i in popular_trip:
    if i in popular_trip:
       c = popular_trip.count(i)
    print(i, '--->' ,c)
    
    
    
# popular_trip.count('[Canal St & Taylor St', 'Canal St & Monroe St (*)]')
# tuple(popular_trip)
# for x in popular_trip:
#     tuple(popular_trip[x])
# print(popular_trip)

# popular_trip.count(1)
# r= Counter(popular_trip)
"""example"""
a = ('Product', '500.00', '1200.00')
a = list(a)
print (a)
a.insert(3, 'foobar')
a = tuple(a)
print (a)
"""something worled finally"""
popular_trip = []  
for x in testing:
    popular_trip += [x['Start Station'],x['End Station']]
    
print(popular_trip)
Counter (popular_trip)
popular_trip = []  
for x in testing:
    popular_trip += [(x['Start Station'],x['End Station'])]
    
print(popular_trip ,'\n')
x= Counter (popular_trip)
y= max(x, key=x.get)
print(y)
popular_trip = []  
for x in testing:
    popular_trip += [[x['Start Station'], x['End Station']]]
    
print(popular_trip)
Counter (popular_trip)
popular_trip = []  
for x in testing:
    popular_trip.append[x['Start Station'], x['End Station']]
    
print(popular_trip)
# Counter (popular_trip)
popular_trip = []  
for x in testing:
    popular_trip.append([x['Start Station'], x['End Station']])
    
print(popular_trip)<jupyter_output>[['Canal St & Taylor St', 'Canal St & Monroe St (*)'], ['Larrabee St & Menomonee St', 'Sheffield Ave & Kingsbury St'], ['Orleans St & Chestnut St (NEXT Apts)', 'Ashland Ave & Blackhawk St'], ['Franklin St & Monroe St', 'Clinton St & Tilden St'], ['Broadway & Barry Ave', 'Sedgwick St & North Ave'], ['State St & Kinzie St', 'Wells St & Polk St'], ['Wabash Ave & Wacker Pl', 'Clinton St & Tilden St'], ['Daley Center Plaza', 'Canal St & Monroe St (*)'], ['Daley Center Plaza', 'Canal St & Monroe St (*)'], ['Dayton St & North Ave', 'Ogden Ave & Chicago Ave'], ['Wilton Ave & Diversey Pkwy', 'Halsted St & Wrightwood Ave'], ['Canal St & Madison St', 'LaSalle St & Illinois St'], ['Theater on the Lake', 'Lakeview Ave & Fullerton Pkwy'], ['Halsted St & Maxwell St', 'Halsted St & 18th St'], ['Ravenswood Ave & Lawrence Ave', 'Clarendon Ave & Gordon Ter']]<jupyter_text>working code<jupyter_code>#one
import csv
from pprint import pprint
import calendar
from collections import Counter

"""This takes the file and returns dict of values. """
with open('chicago.csv', newline='') as csv_file:
    reader = [{key: value for key, value in row.items()}      #list comprehimsion or one liners  {} its s dictionary
    	for row in csv.DictReader(csv_file, skipinitialspace=True)]
    
"""counting the popular trip"""
popular_trip = []  
for x in reader:
    popular_trip += [(x['Start Station'],x['End Station'])]
    
print(popular_trip[0:3] ,'\n')
x= Counter (popular_trip)
y= max(x, key=x.get)
print(y)
import csv
csv.version.version<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.129399703838706, 'fraction_numerical': 0.019592208679804077, 'mean_word_length': 3.8268279274326553, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 26, 'https://': 4, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '112915', 'license': 'MIT', 'n_tokens_mistral': 2974, 'n_tokens_neox': 2730, 'n_words': 955, 'path': 'other/popular_trip.ipynb', 'repo_name': 'chrisdmell/Project_Bikeshare', 'size': '8779'}