These exercises are extremely badly written. Expecting a kvajebajer from author!
name_list = ['Karl', 'Henrik', 'Simone', 'Hercules', 'Jeanne', 'Tahanja']
name_list
['Karl', 'Henrik', 'Simone', 'Hercules', 'Jeanne', 'Tahanja']
only_h = [name for name in name_list if name.startswith("H")]
only_h
['Henrik', 'Hercules']
numbers = [i**3 for i in range(5)]
numbers
[0, 1, 8, 27, 64]
tuples_list = [(len(name), name) for name in name_list]
tuples_list
[(4, 'Karl'), (6, 'Henrik'), (6, 'Simone'), (8, 'Hercules'), (6, 'Jeanne'), (7, 'Tahanja')]
num_string = 'Jeg bliver 24 år den 7 Februar'
## Notice the difference when you cast 'numbers' in an int() and without an int()
result_list_int = [int(numbers) for numbers in num_string.split() if numbers.isdigit()]
print(result_list_int)
result_list_string = [numbers for numbers in num_string.split() if numbers.isdigit()]
print(result_list_string)
[24, 7] ['24', '7']
combos = set([(dice1, dice2) for dice1 in list(range(1,7)) for dice2 in list(range(1, 7))])
combos
{(1, 1), (1, 2), (1, 3), (1, 4), (1, 5), (1, 6), (2, 1), (2, 2), (2, 3), (2, 4), (2, 5), (2, 6), (3, 1), (3, 2), (3, 3), (3, 4), (3, 5), (3, 6), (4, 1), (4, 2), (4, 3), (4, 4), (4, 5), (4, 6), (5, 1), (5, 2), (5, 3), (5, 4), (5, 5), (5, 6), (6, 1), (6, 2), (6, 3), (6, 4), (6, 5), (6, 6)}
name_lengths = {name : len(name) for name in name_list}
name_lengths
{'Karl': 4, 'Henrik': 6, 'Simone': 6, 'Hercules': 8, 'Jeanne': 6, 'Tahanja': 7}
# How do I only put in rounded squareroots of numbers in my dictionary?
# many_numbers = list(range(0, 500))
number_roots = {numbers : numbers**0.5 for numbers in list(range(0, 500))}
number_roots
{0: 0.0, 1: 1.0, 2: 1.4142135623730951, 3: 1.7320508075688772, 4: 2.0, 5: 2.23606797749979, 6: 2.449489742783178, 7: 2.6457513110645907, 8: 2.8284271247461903, 9: 3.0, 10: 3.1622776601683795, 11: 3.3166247903554, 12: 3.4641016151377544, 13: 3.605551275463989, 14: 3.7416573867739413, 15: 3.872983346207417, 16: 4.0, 17: 4.123105625617661, 18: 4.242640687119285, 19: 4.358898943540674, 20: 4.47213595499958, 21: 4.58257569495584, 22: 4.69041575982343, 23: 4.795831523312719, 24: 4.898979485566356, 25: 5.0, 26: 5.0990195135927845, 27: 5.196152422706632, 28: 5.291502622129181, 29: 5.385164807134504, 30: 5.477225575051661, 31: 5.5677643628300215, 32: 5.656854249492381, 33: 5.744562646538029, 34: 5.830951894845301, 35: 5.916079783099616, 36: 6.0, 37: 6.082762530298219, 38: 6.164414002968976, 39: 6.244997998398398, 40: 6.324555320336759, 41: 6.4031242374328485, 42: 6.48074069840786, 43: 6.557438524302, 44: 6.6332495807108, 45: 6.708203932499369, 46: 6.782329983125268, 47: 6.855654600401044, 48: 6.928203230275509, 49: 7.0, 50: 7.0710678118654755, 51: 7.14142842854285, 52: 7.211102550927978, 53: 7.280109889280518, 54: 7.3484692283495345, 55: 7.416198487095663, 56: 7.483314773547883, 57: 7.54983443527075, 58: 7.615773105863909, 59: 7.681145747868608, 60: 7.745966692414834, 61: 7.810249675906654, 62: 7.874007874011811, 63: 7.937253933193772, 64: 8.0, 65: 8.06225774829855, 66: 8.12403840463596, 67: 8.18535277187245, 68: 8.246211251235321, 69: 8.306623862918075, 70: 8.366600265340756, 71: 8.426149773176359, 72: 8.48528137423857, 73: 8.54400374531753, 74: 8.602325267042627, 75: 8.660254037844387, 76: 8.717797887081348, 77: 8.774964387392123, 78: 8.831760866327848, 79: 8.888194417315589, 80: 8.94427190999916, 81: 9.0, 82: 9.055385138137417, 83: 9.1104335791443, 84: 9.16515138991168, 85: 9.219544457292887, 86: 9.273618495495704, 87: 9.327379053088816, 88: 9.38083151964686, 89: 9.433981132056603, 90: 9.486832980505138, 91: 9.539392014169456, 92: 9.591663046625438, 93: 9.643650760992955, 94: 9.695359714832659, 95: 9.746794344808963, 96: 9.797958971132712, 97: 9.848857801796104, 98: 9.899494936611665, 99: 9.9498743710662, 100: 10.0, 101: 10.04987562112089, 102: 10.099504938362077, 103: 10.14889156509222, 104: 10.198039027185569, 105: 10.246950765959598, 106: 10.295630140987, 107: 10.344080432788601, 108: 10.392304845413264, 109: 10.44030650891055, 110: 10.488088481701515, 111: 10.535653752852738, 112: 10.583005244258363, 113: 10.63014581273465, 114: 10.677078252031311, 115: 10.723805294763608, 116: 10.770329614269007, 117: 10.816653826391969, 118: 10.862780491200215, 119: 10.908712114635714, 120: 10.954451150103322, 121: 11.0, 122: 11.045361017187261, 123: 11.090536506409418, 124: 11.135528725660043, 125: 11.180339887498949, 126: 11.224972160321824, 127: 11.269427669584644, 128: 11.313708498984761, 129: 11.357816691600547, 130: 11.40175425099138, 131: 11.445523142259598, 132: 11.489125293076057, 133: 11.532562594670797, 134: 11.575836902790225, 135: 11.61895003862225, 136: 11.661903789690601, 137: 11.704699910719626, 138: 11.74734012447073, 139: 11.789826122551595, 140: 11.832159566199232, 141: 11.874342087037917, 142: 11.916375287812984, 143: 11.958260743101398, 144: 12.0, 145: 12.041594578792296, 146: 12.083045973594572, 147: 12.12435565298214, 148: 12.165525060596439, 149: 12.206555615733702, 150: 12.24744871391589, 151: 12.288205727444508, 152: 12.328828005937952, 153: 12.36931687685298, 154: 12.409673645990857, 155: 12.449899597988733, 156: 12.489995996796797, 157: 12.529964086141668, 158: 12.569805089976535, 159: 12.609520212918492, 160: 12.649110640673518, 161: 12.68857754044952, 162: 12.727922061357855, 163: 12.767145334803704, 164: 12.806248474865697, 165: 12.84523257866513, 166: 12.884098726725126, 167: 12.922847983320086, 168: 12.96148139681572, 169: 13.0, 170: 13.038404810405298, 171: 13.076696830622021, 172: 13.114877048604, 173: 13.152946437965905, 174: 13.19090595827292, 175: 13.228756555322953, 176: 13.2664991614216, 177: 13.30413469565007, 178: 13.341664064126334, 179: 13.379088160259652, 180: 13.416407864998739, 181: 13.45362404707371, 182: 13.490737563232042, 183: 13.527749258468683, 184: 13.564659966250536, 185: 13.601470508735444, 186: 13.638181696985855, 187: 13.674794331177344, 188: 13.711309200802088, 189: 13.74772708486752, 190: 13.784048752090222, 191: 13.820274961085254, 192: 13.856406460551018, 193: 13.892443989449804, 194: 13.92838827718412, 195: 13.96424004376894, 196: 14.0, 197: 14.035668847618199, 198: 14.071247279470288, 199: 14.106735979665885, 200: 14.142135623730951, 201: 14.177446878757825, 202: 14.212670403551895, 203: 14.247806848775006, 204: 14.2828568570857, 205: 14.317821063276353, 206: 14.352700094407323, 207: 14.38749456993816, 208: 14.422205101855956, 209: 14.45683229480096, 210: 14.491376746189438, 211: 14.52583904633395, 212: 14.560219778561036, 213: 14.594519519326424, 214: 14.628738838327793, 215: 14.66287829861518, 216: 14.696938456699069, 217: 14.730919862656235, 218: 14.7648230602334, 219: 14.798648586948742, 220: 14.832396974191326, 221: 14.866068747318506, 222: 14.89966442575134, 223: 14.933184523068078, 224: 14.966629547095765, 225: 15.0, 226: 15.033296378372908, 227: 15.066519173319364, 228: 15.0996688705415, 229: 15.132745950421556, 230: 15.165750888103101, 231: 15.198684153570664, 232: 15.231546211727817, 233: 15.264337522473747, 234: 15.297058540778355, 235: 15.329709716755891, 236: 15.362291495737216, 237: 15.394804318340652, 238: 15.427248620541512, 239: 15.459624833740307, 240: 15.491933384829668, 241: 15.524174696260024, 242: 15.556349186104045, 243: 15.588457268119896, 244: 15.620499351813308, 245: 15.652475842498529, 246: 15.684387141358123, 247: 15.716233645501712, 248: 15.748015748023622, 249: 15.7797338380595, 250: 15.811388300841896, 251: 15.84297951775486, 252: 15.874507866387544, 253: 15.905973720586866, 254: 15.937377450509228, 255: 15.968719422671311, 256: 16.0, 257: 16.0312195418814, 258: 16.06237840420901, 259: 16.09347693943108, 260: 16.1245154965971, 261: 16.15549442140351, 262: 16.186414056238647, 263: 16.217274740226856, 264: 16.24807680927192, 265: 16.278820596099706, 266: 16.30950643030009, 267: 16.34013463836819, 268: 16.3707055437449, 269: 16.401219466856727, 270: 16.431676725154983, 271: 16.46207763315433, 272: 16.492422502470642, 273: 16.522711641858304, 274: 16.55294535724685, 275: 16.583123951777, 276: 16.61324772583615, 277: 16.64331697709324, 278: 16.673332000533065, 279: 16.703293088490067, 280: 16.73320053068151, 281: 16.76305461424021, 282: 16.792855623746664, 283: 16.822603841260722, 284: 16.852299546352718, 285: 16.881943016134134, 286: 16.911534525287763, 287: 16.941074346097416, 288: 16.97056274847714, 289: 17.0, 290: 17.029386365926403, 291: 17.05872210923198, 292: 17.08800749063506, 293: 17.11724276862369, 294: 17.146428199482248, 295: 17.175564037317667, 296: 17.204650534085253, 297: 17.233687939614086, 298: 17.26267650163207, 299: 17.291616465790582, 300: 17.320508075688775, 301: 17.349351572897472, 302: 17.378147196982766, 303: 17.406895185529212, 304: 17.435595774162696, 305: 17.46424919657298, 306: 17.4928556845359, 307: 17.52141546793523, 308: 17.549928774784245, 309: 17.578395831246947, 310: 17.60681686165901, 311: 17.635192088548397, 312: 17.663521732655695, 313: 17.69180601295413, 314: 17.72004514666935, 315: 17.74823934929885, 316: 17.776388834631177, 317: 17.804493814764857, 318: 17.832554500127006, 319: 17.86057109949175, 320: 17.88854381999832, 321: 17.916472867168917, 322: 17.944358444926362, 323: 17.97220075561143, 324: 18.0, 325: 18.027756377319946, 326: 18.05547008526779, 327: 18.083141320025124, 328: 18.110770276274835, 329: 18.138357147217054, 330: 18.16590212458495, 331: 18.193405398660254, 332: 18.2208671582886, 333: 18.24828759089466, 334: 18.275666882497067, 335: 18.303005217723125, 336: 18.33030277982336, 337: 18.35755975068582, 338: 18.384776310850235, 339: 18.411952639521967, 340: 18.439088914585774, 341: 18.466185312619388, 342: 18.49324200890693, 343: 18.520259177452136, 344: 18.547236990991408, 345: 18.57417562100671, 346: 18.601075237738275, 347: 18.627936010197157, 348: 18.65475810617763, 349: 18.681541692269406, 350: 18.708286933869708, 351: 18.734993995195193, 352: 18.76166303929372, 353: 18.788294228055936, 354: 18.81488772222678, 355: 18.841443681416774, 356: 18.867962264113206, 357: 18.894443627691185, 358: 18.920887928424502, 359: 18.947295321496416, 360: 18.973665961010276, 361: 19.0, 362: 19.026297590440446, 363: 19.05255888325765, 364: 19.078784028338912, 365: 19.1049731745428, 366: 19.131126469708992, 367: 19.157244060668017, 368: 19.183326093250876, 369: 19.209372712298546, 370: 19.235384061671343, 371: 19.261360284258224, 372: 19.28730152198591, 373: 19.313207915827967, 374: 19.339079605813716, 375: 19.364916731037084, 376: 19.390719429665317, 377: 19.4164878389476, 378: 19.44222209522358, 379: 19.467922333931785, 380: 19.493588689617926, 381: 19.519221295943137, 382: 19.544820285692065, 383: 19.570385790780925, 384: 19.595917942265423, 385: 19.621416870348583, 386: 19.6468827043885, 387: 19.672315572906, 388: 19.697715603592208, 389: 19.72308292331602, 390: 19.748417658131498, 391: 19.77371993328519, 392: 19.79898987322333, 393: 19.82422760159901, 394: 19.849433241279208, 395: 19.87460691435179, 396: 19.8997487421324, 397: 19.924858845171276, 398: 19.949937343260004, 399: 19.974984355438178, 400: 20.0, 401: 20.024984394500787, 402: 20.049937655763422, 403: 20.074859899884732, 404: 20.09975124224178, 405: 20.12461179749811, 406: 20.149441679609886, 407: 20.174241001832016, 408: 20.199009876724155, 409: 20.223748416156685, 410: 20.248456731316587, 411: 20.273134932713294, 412: 20.29778313018444, 413: 20.322401432901575, 414: 20.346989949375804, 415: 20.37154878746336, 416: 20.396078054371138, 417: 20.42057785666214, 418: 20.445048300260872, 419: 20.46948949045872, 420: 20.493901531919196, 421: 20.518284528683193, 422: 20.54263858417414, 423: 20.566963801203133, 424: 20.591260281974, 425: 20.615528128088304, 426: 20.639767440550294, 427: 20.663978319771825, 428: 20.688160865577203, 429: 20.71231517720798, 430: 20.73644135332772, 431: 20.760539492026695, 432: 20.784609690826528, 433: 20.808652046684813, 434: 20.83266665599966, 435: 20.85665361461421, 436: 20.8806130178211, 437: 20.904544960366874, 438: 20.92844953645635, 439: 20.952326839756964, 440: 20.97617696340303, 441: 21.0, 442: 21.02379604162864, 443: 21.047565179849187, 444: 21.071307505705477, 445: 21.095023109728988, 446: 21.118712081942874, 447: 21.142374511865974, 448: 21.166010488516726, 449: 21.18962010041709, 450: 21.213203435596427, 451: 21.236760581595302, 452: 21.2602916254693, 453: 21.283796653792763, 454: 21.307275752662516, 455: 21.330729007701542, 456: 21.354156504062622, 457: 21.37755832643195, 458: 21.400934559032695, 459: 21.42428528562855, 460: 21.447610589527216, 461: 21.470910553583888, 462: 21.494185260204677, 463: 21.517434791350013, 464: 21.540659228538015, 465: 21.563858652847824, 466: 21.587033144922902, 467: 21.61018278497431, 468: 21.633307652783937, 469: 21.656407827707714, 470: 21.6794833886788, 471: 21.702534414210707, 472: 21.72556098240043, 473: 21.748563170931547, 474: 21.77154105707724, 475: 21.79449471770337, 476: 21.817424229271428, 477: 21.840329667841555, 478: 21.863211109075447, 479: 21.88606862823929, 480: 21.908902300206645, 481: 21.93171219946131, 482: 21.95449840010015, 483: 21.97726097583591, 484: 22.0, 485: 22.02271554554524, 486: 22.045407685048602, 487: 22.06807649071391, 488: 22.090722034374522, 489: 22.11334438749598, 490: 22.135943621178654, 491: 22.15851980616034, 492: 22.181073012818835, 493: 22.20360331117452, 494: 22.22611077089287, 495: 22.24859546128699, 496: 22.271057451320086, 497: 22.293496809607955, 498: 22.315913604421397, 499: 22.338307903688676}